I don't know what other code I could give besides the graphical functions for Draw battle. All I'm trying to do is figure out how deduct health in random increments from two different structures. Ive given the structures for both player and monsters. Each has values for attack health and defense.
Here is the whole sketch page with everything I have for draw battle. It is pulled up randomly and includes a menu system for attack, item and flee
#ifndef _Battle_H_
#define _Battle_H_
#include "Player.h"
#include "Variables.h"
#include "Bitmaps.h"
#define Monster_Cave_spider 1
#define Monster_Desert_bat 2
#define Monster_Desert_hare 3
#define Monster_Desert_scorpion 4
#define Monster_Desert_slig 5
#define Monster_Face_dancer 6
#define Monster_Jacuruto_outcast 7
#define Monster_Kangaroo_mouse 8
#define Monster_Laza_tiger 9
#define Monster_Sandworm 10
struct Monster {
int x;
int y;
int w;
int h;
uint8_t MonId;
uint8_t Attack;
uint8_t Defense;
uint8_t Health;
};
Monster monsters[] = {
{143, 150, 34, 24, 1, 10, 5, 20},
{143, 150, 48, 40, 2, 10, 5, 20},
{143, 150, 34, 22, 3, 15, 10, 30},
{143, 150, 44, 34, 4, 20, 15, 40},
{143, 150, 28, 36, 5, 20, 15, 40},
{143, 150, 34, 40, 6, 20, 20, 50},
{143, 150, 34, 32, 7, 20, 30, 60},
{143, 150, 38, 36, 8, 10, 5, 20},
{143, 150, 44, 32, 9, 30, 40, 70},
{143, 150, 24, 24, 10, 40, 50, 80},
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const char * getMonsterName(uint8_t MonId)
{
switch (MonId)
{
case 1: return "Cave Spider";
case 2: return "Desert Bat";
case 3: return "Desert Hare";
case 4: return "Desert Scorpion";
case 5: return "Deset Slig";
case 6: return "Facedancer";
case 7: return "Jacuruto Outcast";
case 8: return "Kangaroo Mouse";
case 9: return "Laza Tiger";
case 10: return "Sandworm";
}
}
void monsterAttk(){
uint8_t hploss = (player.health = (player.health - random(0, 20+1)));
Serial.println(hploss);
}
void drawBattle() {
monsterAttk();
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Palette////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
palette[0] = 0; palette[8] = BEIGE;
palette[1] = BLACK; palette[9] = GREEN;
palette[2] = BLUE; palette[a] = DARKGREY;
palette[3] = BROWN; palette[b] = LIGHTGREY;
palette[4] = DARKGREEN; palette[c] = YELLOW;
palette[5] = GREY; palette[d] = PURPLE;
palette[6] = PINK; palette[e] = WHITE;
palette[7] = RED; palette[f] = ORANGE;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Rect rectC {24, 138, 33, 7};
Rect rectD {24, 164, 22, 7};
Rect rectE {24, 190, 47, 7};
Rect rectF {24, 216, 23, 7};
Rect rectG {cursorb.cursorB_x, cursorb.cursorB_y, 32, 32};
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
tft.fillScreen(BLACK);
tft.fillRect(0, 30, 320, 50, WHITE); ////// draws a back grounds stripe for the monsters to sit on the length nof the screen
tft.writeRectNBPP(143, 50, 34, 24, 4, cavespider, palette);
tft.drawRoundRect(40, 82, 240, 40, 4, WHITE);
tft.fillRoundRect(41, 83, 237, 36, 4, BLUE);
tft.setCursor(90, 94);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Cave spider");
tft.fillRoundRect(10, 130, 119, 106, 4, WHITE);
tft.fillRoundRect(14, 133, 111, 100, 4, BLUE);
tft.setCursor(24, 138);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Attack");
tft.setCursor(24, 164);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Item");
tft.setCursor(24, 190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Weirding");
tft.setCursor(24, 216);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Flee");
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int y1 = ss1.analogRead(2);
int x1 = ss1.analogRead(3);
///////////////////////////////////////////////////////////////////////////////
////////////////////////////Up/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (x1 > 600 && last_x < 600) {
tft.writeRectNBPP(cursorb.cursorB_x, cursorb.cursorB_y, 32, 32, 4, cursor3, palette);
cursorb.cursorB_y -= 26;
}
if (cursorb.cursorB_y <= 136) {
cursorb.cursorB_y = 136;
}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Down///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (x1 < 400 && last_x > 400) {
tft.writeRectNBPP(cursorb.cursorB_x, cursorb.cursorB_y, 32, 32, 4, cursor3, palette);
cursorb.cursorB_y += 26;
}
if (cursorb.cursorB_y >= 240) {
cursorb.cursorB_y = 240;
}
last_x = x1;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (cursorb.cursorB_direction == 1) {
tft.writeRectNBPP(cursorb.cursorB_x, cursorb.cursorB_y, 32, 32, 4, cursor3, palette);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!digitalRead(IRQ_PIN2)) {
uint32_t buttons = ss2.digitalReadBulk(button_mask2);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((! (buttons & (1 << BUTTON_X)) && tft.collideRectRect( rectC.x, rectC.y, rectC.width, rectC.height, rectG.x, rectG.y, rectG.width, rectG.height)))
{
tft.fillScreen(GREEN);
}
else if ((! (buttons & (1 << BUTTON_X)) && tft.collideRectRect( rectD.x, rectD.y, rectD.width, rectD.height, rectG.x, rectG.y, rectG.width, rectG.height)))
{
state = STATE_Item_list_bat;
}
else if ((! (buttons & (1 << BUTTON_X)) && tft.collideRectRect( rectE.x, rectE.y, rectE.width, rectE.height, rectG.x, rectG.y, rectG.width, rectG.height)))
{
tft.fillScreen(PURPLE);
}
else if ((! (buttons & (1 << BUTTON_X)) && tft.collideRectRect( rectF.x, rectF.y, rectF.width, rectF.height, rectG.x, rectG.y, rectG.width, rectG.height)))
{
state = STATE_Player;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
#endif
I use a collision function for the cursor which collides with each menu choice and when a button is pressed it performs the action with in each set of brackets