RPG advice and development

Hi Guys

Im working on dune RPG for a full color off shoot based on the Arduboy library. I want to be able to switch rooms or go from worldmap to dungeon. I have some old code that I was working on but I just recently picked it back up due to trying to complete my library. The libraries can be found here for reference…

ok so here is the code…

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;



const byte tilemap1[] PROGMEM = {17,11,
8,8,

 2, 2, 2, 2, 2, 2, 2, 2,26,26,26,26,26,26,26,26, 2,
 2, 2, 2, 2, 2, 2, 2,19,26,26,26,26,26,26,26,26,20,
 2, 2, 2, 2, 2, 2, 2,19,25,26,26,25,25,25,25,25,20,
 2, 2, 2, 2, 2, 2,18, 4, 8,25,26,56,57,58,59,60,20,
 2, 2, 2, 2, 2, 4, 8, 8, 8, 8,25,51,52,53,54,55,20,
 2, 2, 2, 2, 4, 8, 8, 8, 8, 8, 8,46,47,48,49,50,20,  /////////112x64 pix res
18,18,18, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 3,
28, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,29,
21,21, 6, 8, 8, 8,22,23,24, 8, 8, 8, 8, 8, 5,21,21,
 2, 2,19, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,20, 2, 2,
 2, 2, 2,21,21,21,21,21,21,21,21,21,21,21, 2, 2, 2};

const byte tilemap2[] PROGMEM = {17,11,
8,8,
 2, 2, 2, 2, 2, 2, 2,19,30,30, 3,18,18,18,18,18, 2,
 2, 2, 2, 2, 2, 2, 2,19, 8, 8,27,27,27,27,27,27,20,
 2, 2, 2, 2, 2, 2, 2,19, 8, 8,26,26,26,26,26,26,20,
 2, 2, 2, 2, 2, 2,18, 4, 8, 8,25,26,26,26,26,26,20,
 2, 2, 2, 2, 2, 4, 8, 8, 8, 8, 8,26,26,26,26,26,20,
 2, 2, 2, 2, 4, 8, 8, 8, 8, 8, 8,26,26,26,26,26,20,  /////////112x64 pix res
18,18,18, 4, 8, 8, 8,27, 8, 8, 8, 8,25,25,25,25, 3,
28, 8, 8, 8, 8, 8,27,26,27, 8, 8, 8, 8, 8, 8, 8,29,
21,21, 6, 8, 8,27,26,26,26,27, 8, 8, 8, 8, 5,21,21,
 2, 2,19, 8, 8,25,25,25,25,25, 8, 8, 8, 8,20, 2, 2,
 2, 2, 2,21,21,21,21,21,21,21,21,21,21,21, 2, 2, 2};

const byte tilemap3[] PROGMEM = {17,11,
8,8,
 2, 2, 2, 2, 2, 2, 2, 2,18,18,18,18,18,18,18,18, 2,
 2, 2, 2, 2, 2, 2, 2,19, 8, 8, 8, 8, 8, 8, 8, 8,20,
 2, 2, 2, 2, 2, 2, 2,19, 8, 8, 8, 8, 8, 8, 8, 8,20,
 2,18,18,18,18,18,18, 4, 8, 8, 8, 8, 5,21,21,21, 2,
19, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 2, 2, 2, 2, 2,
19, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 2, 2, 2, 2, 2, 2,  /////////112x64 pix res
19, 8, 8, 5,21,21,21, 6, 8, 8,20, 2, 2, 2, 2, 2, 2,
19, 8, 8,20, 2, 2, 2,19, 8, 8,20, 2, 2, 2, 2, 2, 2,
19,34, 8,20, 2, 2, 2,19, 8, 8,20, 2, 2, 2, 2, 2, 2,
 2,21,21, 2, 2, 2, 2,19, 8, 8,20, 2, 2, 2, 2, 2, 2,
 2, 2, 2, 2, 2, 2, 2,19,28,28,20, 2, 2, 2, 2, 2, 2};

const byte tilemap4[] PROGMEM = {17,11,
8,8,
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 2,18,18,18,18,18, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19, 8, 8, 8,36, 8,20, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19, 8, 8, 8, 8, 8,20, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,  /////////112x64 pix res
19, 8, 8, 5,21,21, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19, 8, 8,20, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19,35, 8,20, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 2,21,21, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};

 const byte tilemap5[] PROGMEM = {12,11,
8,8,
45,45,45,45,45,45,45,45,45,45,45,45,
45,45,37,37,37,37,37,37,37,45,45,45,
45,41,61,61,61,61,61,62,61,40,45,45,
45,41, 8, 8, 8, 8, 8,63, 8,40,45,45,
45,41, 8, 8, 8, 8, 8,64, 8,40,45,45,
45,41, 8, 8, 8, 8, 8, 8, 8,40,45,45,  /////////112x64 pix res
45,41, 8, 8, 8, 8, 8, 8, 8,40,45,45,
45,41, 8, 8, 8, 8, 8, 8, 8,40,45,45,
45,41, 8, 8, 8, 8, 8, 8, 8,40,45,45,
45,45,42,42,44, 8,43,42,42,45,45,45,
45,45,45,45,41,28,40,45,45,45,45,45,};

const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B00000010,B00010000,B01000000,B00000010,B00010000,B00001000,B01000001,B00000100,};
const byte rock_valley_ne[] PROGMEM = {B10100000,B11001001,B01110000,B00001100,B00000101,B00000100,B00000110,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B00000101,B10010011,B00001110,B00110000,B10100000,B00100000,B01100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000110,B00000100,B00000101,B00001100,B01110000,B11001001,B10100000,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B01100000,B00100000,B10100000,B00110000,B00001110,B10010011,B00000101,};
const byte turtle_rock[] PROGMEM = {B01101100,B10110010,B11010001,B01010101,B01010010,B10011001,B10000001,B11111110,};
const byte void_tile[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte water_left_bottom[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B11111111,};
const byte water_left_middle[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B10000000,};
const byte water_left_top[] PROGMEM = {B11111111,B10000000,B11110000,B10001111,B10000000,B10000000,B11110000,B10000000,};
const byte water_right_bottom[] PROGMEM = {B1110001,B00000001,B0000111,B00000001,B11110001,B00000001,B00001111,B11111111,};
const byte water_right_middle[] PROGMEM = {B11110001,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_right_top[] PROGMEM = {B11111111,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_middle_bottom[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B11111111,};
const byte water_middle_middle[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B00000000,};
const byte water_middle_top[] PROGMEM = {B11111111,B00000000,B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,};
const byte rock_s[] PROGMEM = {B00010010,B00000000,B01001000,B00000100,B00100001,B10001100,B01110010,B10000001,};
const byte rock_e[] PROGMEM = {B00000101,B00100010,B00001010,B10000010,B00100100,B00010100,B10000010,B00001001,};
const byte rock_n[] PROGMEM = {B10000001,B01110010,B10001100,B00100001,B00000100,B01001000,B00000000,B00010010,};
const byte rock_w[] PROGMEM = {B10100000,B01000100,B01010000,B01000001,B00100100,B00101000,B01000001,B10010000,};
const byte bush_left[] PROGMEM = {B00111011,B01000100,B10100000,B10010100,B01000010,B10000000,B10001000,B01110111,};
const byte bush_middle[] PROGMEM = {B10111101,B01000010,B00001000,B10000100,B00010000,B00100001,B10001000,B01110111,};
const byte bush_right[] PROGMEM = {B11011100,B00100010,B00000101,B00101001,B01000010,B00000001,B00010001,B11101110,};
const byte tree_base[] PROGMEM = {B01010100,B01000100,B10100010,B10001010,B10000010,B01101100,B00101000,B00101000,};
const byte tree_repeat[] PROGMEM = {B01010100,B01000100,B10000010,B10010010,B10101010,B01101100,B00101000,B01000100,};
const byte tree_top[] PROGMEM = {B00000000,B00000000,B00000000,B00010000,B00101000,B00101000,B00101000,B01000100,};
const byte exit_1[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte exit_2[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte exit_3[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte exit_4[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte exit_5[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte exit_6[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte cave_ladder[] PROGMEM = {B11000011,B11011011,B11000011,B11011011,B11000011,B11011011,B11000011,B11011011,};
const byte ladder[] PROGMEM = {B00111100,B00100100,B00111100,B00100100,B00111100,B00100100,B00111100,B00100100,};
const byte tombstone[] PROGMEM = {B00111100,B01000010,B10000001,B10111001,B10000001,B10101101,B10000001,B11111111,};
const byte WallB[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B11111111,};
const byte WallBL[] PROGMEM = {B10111111,B10111111,B10111111,B10111111,B10111111,B10111111,B10000000,B11111111,};
const byte WallBR[] PROGMEM = {B11111101,B11111101,B11111101,B11111101,B11111101,B11111101,B00000001,B11111111,};
const byte WallL[] PROGMEM = {B10111111,B10111111,B10111111,B10111111,B10111111,B10111111,B10111111,B10111111,};
const byte WallR[] PROGMEM = {B11111101,B11111101,B11111101,B11111101,B11111101,B11111101,B11111101,B11111101,};
const byte WallT[] PROGMEM = {B11111111,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte WallTL[] PROGMEM = {B11111111,B10000000,B10111111,B10111111,B10111111,B10111111,B10111111,B10111111,};
const byte WallTR[] PROGMEM = {B11111111,B00000001,B11111101,B11111101,B11111101,B11111101,B11111101,B11111101,};
const byte blackwall[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte houseB1[] PROGMEM = {B01010011,B01010010,B01010010,B01010001,B11110000,B10011111,B10010010,B11111111,};
const byte houseB2[] PROGMEM = {B11111000,B01001000,B01001000,B11110000,B00000000,B11111111,B01001000,B11111111,};
const byte houseB3[] PROGMEM = {B00111100,B01100110,B11000011,B10011001,B10000001,B10000101,B10000001,B11111111,};
const byte houseB4[] PROGMEM = {B00011111,B00010010,B00010010,B00001111,B00000000,B11111111,B00010010,B11111111,};
const byte houseB5[] PROGMEM = {B11001010,B01001010,B01001010,B10001010,B00001111,B11111001,B01001001,B11111111,};
const byte houseT1[] PROGMEM = {B11111111,B01010010,B01011111,B01010000,B01010000,B11110001,B10010010,B11110010,};
const byte houseT2[] PROGMEM = {B11111111,B01001001,B11111111,B00000000,B00000000,B11110000,B01001000,B01001000,};
const byte houseT3[] PROGMEM = {B11111111,B00100100,B11111111,B00000000,B01111110,B10100101,B11111111,B00000000,};
const byte houseT4[] PROGMEM = {B11111111,B10010010,B11111111,B00000000,B00000000,B00001111,B00010010,B00010010,};
const byte houseT5[] PROGMEM = {B11111111,B01001010,B11111010,B00001010,B00001010,B10001111,B01001001,B01001111,};
const byte roof1[] PROGMEM = {B00000000,B00011111,B00110010,B00101101,B01000000,B01010010,B11101101,B10000000,};
const byte roof2[] PROGMEM = {B00000000,B11111111,B01001001,B10110110,B00000000,B01001001,B10110110,B00000000,};
const byte roof3[] PROGMEM = {B00000000,B11111111,B00100100,B11011011,B00000000,B00100100,B11011011,B00000000,};
const byte roof4[] PROGMEM = {B00000111,B11111100,B10010111,B01101100,B00000100,B10010111,B01101101,B00000000,};
const byte roof5[] PROGMEM = {B10000000,B11111000,B11001100,B10110100,B10000010,B11001010,B10110111,B00000001,};
const byte wallpaper[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,};
const byte bedbottom[] PROGMEM = {B10111101,B11000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte bedmid[] PROGMEM = {B11111111,B10000001,B10000001,B10000001,B10111101,B11000011,B10000001,B10000001,};
const byte bedtop[] PROGMEM = {B00000000,B00000000,B00000000,B00111100,B11000011,B10000001,B10111101,B10100101,};





const byte *spritesheet[] = {bush,    //0
port_noir,                            //1
rock_terrain_master,                  //2
rock_valley_ne,                       //3
rock_valley_nw,                       //4
rock_valley_se,                       //5
rock_valley_sw,                       //6
turtle_rock,                          //7
void_tile,                            //8
water_left_bottom,                    //9
water_left_middle,                    //10
water_left_top,                       //11
water_right_bottom,                   //12
water_right_middle,                   //13
water_right_top,                      //14
water_middle_bottom,                  //15
water_middle_middle,                  //16
water_middle_top,                     //17
rock_s,                               //18
rock_e,                               //19
rock_w,                               //20
rock_n,                               //21
bush_left,                            //22
bush_middle,                          //23
bush_right,                           //24
tree_base,                            //25
tree_repeat,                          //26
tree_top,                             //27
exit_1,                               //28
exit_2,                               //29
exit_3,                               //30
exit_4,                               //31
exit_5,                               //32
exit_6,                               //33
cave_ladder,                          //34
ladder,                               //35
tombstone,                            //36
WallB,                                //37
WallBL,                               //38
WallBR,                               //39
WallL,                                //40
WallR,                                //41
WallT,                                //42
WallTL,                               //43
WallTR,                               //44
blackwall,                            //45
houseB1,                              //46
houseB2,                              //47
houseB3,                              //48
houseB4,                              //49
houseB5,                              //50
houseT1,                              //51
houseT2,                              //52
houseT3,                              //53
houseT4,                              //54
houseT5,                              //55
roof1,                                //56
roof2,                                //57
roof3,                                //58
roof4,                                //59
roof5,                                //60
wallpaper,                            //61
bedtop,                               //62
bedmid,                               //63
bedbottom};                           //64

const byte backblack[] PROGMEM = {8,8,0x7E,0x42,0x42,0x3C,0x7E,0x3C,0x3C,0x24,};
const byte backgrey[] PROGMEM = {8,8,0x1,0x1,0x1,0xC1,0x81,0xC0,0x40,0x0,};
const byte frontblack[] PROGMEM = {8,8,0x7E,0x66,0x42,0x38,0x78,0x38,0x3C,0x24,};
const byte frontgrey[] PROGMEM = {8,8,0x80,0x80,0x80,0x87,0x87,0x7,0x2,0x0,};
const byte leftblack[] PROGMEM = {8,8,0x3E,0x32,0x22,0x1C,0x1C,0x1C,0x1C,0x14,};
const byte leftgrey[] PROGMEM = {8,8,0x0,0x0,0x0,0x60,0x60,0x60,0x40,0x0,};
const byte rightblack[] PROGMEM = {8,8,0x7C,0x4C,0x44,0x38,0x3C,0x38,0x38,0x28,};
const byte rightgrey[] PROGMEM = {8,8,0x2,0x2,0x2,0x2,0x2,0x0,0x0,0x0,};


  int player_x = 70;    //cant get these to center
  int player_y = 40;    //cant get these to center
  int player_direction = 0;
  int room = 1;
  int co_ords = 1;

int x,y; ///if 0 player spite will not move, -50,50 no tilemap

//////CAMERA//////
int camerax = -20 ;
int cameray = -20 ;
int animTransition;


void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.setFrameRate(62);  ////////for sprite
  gb.display.persistence = false;
//  animTransition=-6;
}

/////////PLAYER_MOVEMENT\\\\\\\\\

void loop() {
  if(gb.update()){
    if (gb.buttons.repeat(BTN_RIGHT,1));{x--;}
    if (gb.buttons.repeat(BTN_LEFT,1));{x++;}
    if (gb.buttons.repeat(BTN_DOWN,1));{y--;}
    if (gb.buttons.repeat(BTN_UP,1));{y++;}


//      if(player_x > 64 ) {camerax-=2; player_x -=2;}    //Y Scrolling  right
//else  if(player_x < 10 ){camerax+=2; player_x +=2;}   //Y Scrolling  left
  
//        if(player_y > 28 ) {cameray-=2; player_y -=2;}    //Y Scrolling  Down
//else  if(player_y < 10 ){cameray+=2; player_y +=2;}   //Y Scrolling  Up

//      if(cameray > 0)cameray=0;   
//else  if(cameray < -24) cameray = -24;
//      if(camerax > 0)camerax=0;   
//else  if(camerax < -36) camerax = -36;

if(player_x > 59 && camerax <  0 && camerax  > -52){player_x = 59;camerax--;}
else  if(player_x < 15 && camerax <  0 && camerax  > -52){player_x = 15;camerax++;}
else  if(player_x > 59 && camerax <= 0 && camerax >= -52)camerax--;
else  if(player_x < 15 && camerax <= 0 && camerax >= -52)camerax++;   
  
  
      if(player_y > 28 && cameray < 0 && cameray >  -40){player_y = 28;cameray--;}
else  if(player_y < 15 && cameray < 0 && cameray >  -40){player_y = 15;cameray++;}
else  if(player_y > 28 && cameray <= 0 && cameray >= -40)cameray--;
else  if(player_y < 15 && cameray <= 0 && cameray >= -40)cameray++;  

      if(camerax > 0)camerax= 0;
else  if(camerax < -52) camerax = -52;
  
      if(cameray > 0)cameray= 0;   
else  if(cameray < -40) cameray = -40;

  if(room == 1){
    gb.display.drawTilemap(camerax,cameray,tilemap1,spritesheet);} // draw the tilemap
 //  gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );
  if(room == 2){
    gb.display.clear();
   gb.display.drawTilemap(camerax,cameray,tilemap2,spritesheet);} // draw the tilemap
 //   gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );
  if(room == 3){
    gb.display.clear();
   gb.display.drawTilemap(camerax,cameray,tilemap3,spritesheet);} // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );
  if(room == 4){
    gb.display.clear();
   gb.display.drawTilemap(camerax,cameray,tilemap4,spritesheet);} // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );
  if(room == 5){
    gb.display.clear();
   gb.display.drawTilemap(camerax,cameray,tilemap5,spritesheet);} // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );



//if(gb.buttons.repeat(BTN_A,1)){
//    gb.display.setColor(BLACK);
//    gb.display.fillRect(0,0,84,48);
//    gb.display.setColor(WHITE);
//    gb.display.fillRect(animTransition,animTransition,84-(2*animTransition),48-(2*animTransition));
//    gb.display.setColor(BLACK);
//    {animTransition = animTransition + 6;}
//  }
//  if(gb.buttons.repeat(BTN_B,1)){
//    gb.display.setColor(BLACK);
//    gb.display.fillRect(0,0,84,48);
//    gb.display.setColor(WHITE);
//    gb.display.fillRect(animTransition,animTransition,84-(2*animTransition),48-(2*animTransition));
//    gb.display.setColor(BLACK);
//    {animTransition = animTransition - 6;}
//  }

 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,backblack);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,backgrey);
    }
      player_direction = 1;
      player_y = player_y - 1;
      if(checkcolision())player_y++;  // ADD by Summoner123 - If have colision on the new position regreat one Pixel
      }

      
    if(player_y <= 0){
      player_y = 0;}



    if(gb.buttons.repeat(BTN_DOWN,1)){
      gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,frontblack);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,frontgrey);
    } 
      player_direction = 2;
      player_y = player_y + 1;
      if(checkcolision())player_y--;  // ADD by Summoner123 - If have colision on the new position regreat one Pixel
      }
      
    if(player_y >= 40){
      player_y = 40;}
  


    if(gb.buttons.repeat(BTN_RIGHT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,rightblack);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,rightgrey);
    }
      player_direction = 3;
      player_x = player_x + 1;
      if(checkcolision())player_x--;  // ADD by Summoner123 - If have colision on the new position regreat one Pixel
      }
      
      
    if(player_x >= 77){
      player_x = 77;}


    if(gb.buttons.repeat(BTN_LEFT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,leftblack);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,leftgrey);
    }
      player_direction = 4;
      player_x = player_x - 1;
      
      if(checkcolision())player_x++;  // ADD by Summoner123 - If have colision on the new position regreat one Pixel
      }
      
    if(player_x <= -2){
      player_x = -2;}
      
      ////////////PLAYER DIRECTION/////////////

 if (player_direction == 1){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,backblack);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,backgrey);
        }
 }
      
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,frontblack);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,frontgrey);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,rightblack);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,rightgrey);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,leftblack);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,leftgrey);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,frontblack);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,frontgrey);
        }
      }
} 
  

gb.display.setColor(BLACK);

if(gb.buttons.held(BTN_B,20)){
    co_ords = co_ords + 1;}

if(co_ords == 1){
  gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );}
else if(co_ords == 2){
  gb.display.cursorY = 12; gb.display.println( camerax );gb.display.println( cameray );}
else if(co_ords >= 3){
    co_ords = 0;}

}



     bool checkcolision() // Transformed it into a function
   {
    uint16_t i;
     for(i=0; i < gb.display.numcolision + 1; i++)
   {
    if(gb.collideRectRect(player_x,player_y,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))///changed player_x,y back to 8
    {
        //  if(gb.display.solid[i].spritecol == void_tile); //Do nothing because it's floor - This line not needed
          if(gb.display.solid[i].spritecol == bush) return true;
else      if(gb.display.solid[i].spritecol == port_noir) return true;
else      if(gb.display.solid[i].spritecol == rock_terrain_master) {gb.popup(F(" ""Rock"" "),1); return true;} //Return True if character have touched the wall
else      if(gb.display.solid[i].spritecol == rock_valley_ne) return true;
else      if(gb.display.solid[i].spritecol == rock_valley_nw) return true;
else      if(gb.display.solid[i].spritecol == rock_valley_se) return true;
else      if(gb.display.solid[i].spritecol == rock_valley_sw) return true;
else      if(gb.display.solid[i].spritecol == turtle_rock) return true;
else      if(gb.display.solid[i].spritecol == water_left_bottom) return true;
else      if(gb.display.solid[i].spritecol == water_left_middle) return true;
else      if(gb.display.solid[i].spritecol == water_left_top) return true;
else      if(gb.display.solid[i].spritecol == water_right_bottom) return true;
else      if(gb.display.solid[i].spritecol == water_right_middle) return true;
else      if(gb.display.solid[i].spritecol == water_right_top) return true;
else      if(gb.display.solid[i].spritecol == water_middle_bottom) return true;
else      if(gb.display.solid[i].spritecol == water_middle_middle) return true;
else      if(gb.display.solid[i].spritecol == water_middle_top) return true;
else      if(gb.display.solid[i].spritecol == rock_n) return true;
else      if(gb.display.solid[i].spritecol == rock_e) return true;
else      if(gb.display.solid[i].spritecol == rock_s) return true;
else      if(gb.display.solid[i].spritecol == rock_w) return true;
else      if(gb.display.solid[i].spritecol == bush_left) return true;
else      if(gb.display.solid[i].spritecol == bush_middle) return true;
else      if(gb.display.solid[i].spritecol == bush_right) return true;
//else      if(gb.display.solid[i].spritecol == bush_left) {gb.popup(F(" ""A bush!!"" "),1); return true;}
//else      if(gb.display.solid[i].spritecol == bush_middle) {gb.popup(F(" ""A bush!!"" "),1); return true;}
//else      if(gb.display.solid[i].spritecol == bush_right) {gb.popup(F(" ""A bush!!"" "),1); return true;}
else      if(gb.display.solid[i].spritecol == tree_base) return true;
else      if(gb.display.solid[i].spritecol == tree_repeat) return true;
else      if(gb.display.solid[i].spritecol == tree_top) return true;
else      if((gb.display.solid[i].spritecol == exit_1) && room == 1) {room = 2; player_x = 68; camerax = -52;}
else      if((gb.display.solid[i].spritecol == exit_1) && room == 2) {room = 1; player_x = 68; camerax = -52;}
else      if((gb.display.solid[i].spritecol == exit_1) && room == 3) {room = 2; player_y = 9; cameray = 0;}
else      if((gb.display.solid[i].spritecol == exit_1) && room == 5) {room = 1; player_y = 27; player_x = 59; camerax = -45; cameray = -21;}
else      if((gb.display.solid[i].spritecol == exit_2) && room == 1) {room = 2; player_x = 9; camerax = 0;}
else      if((gb.display.solid[i].spritecol == exit_2) && room == 2) {room = 1; player_x = 9; camerax = 0;}
else      if((gb.display.solid[i].spritecol == exit_3) && room == 2) {room = 3; player_y = 32; cameray = -40;}
else      if(gb.display.solid[i].spritecol == exit_4) return true;
else      if(gb.display.solid[i].spritecol == exit_5) return true;
else      if(gb.display.solid[i].spritecol == exit_6) return true;
else      if((gb.display.solid[i].spritecol == cave_ladder) && room ==3) {room = 4; player_x = 16; player_y = 24; camerax = 0; cameray = -48;}
else      if((gb.display.solid[i].spritecol == ladder) && room == 4) {room  = 3; player_x = 16; player_y = 24; camerax = 0; cameray = -48;}
else      if((gb.display.solid[i].spritecol == tombstone) && gb.buttons.repeat(BTN_A,1)) {gb.popup(F(" ""Here Lies Dave!"" "),1); return true;}
else      if(gb.display.solid[i].spritecol == tombstone) return true;
else      if(gb.display.solid[i].spritecol == WallB) return true;
else      if(gb.display.solid[i].spritecol == WallBL) return true;
else      if(gb.display.solid[i].spritecol == WallBR) return true;
else      if(gb.display.solid[i].spritecol == WallT) return true;
else      if(gb.display.solid[i].spritecol == WallTL) return true;
else      if(gb.display.solid[i].spritecol == WallTR) return true;
else      if(gb.display.solid[i].spritecol == WallL) return true;
else      if(gb.display.solid[i].spritecol == WallR) return true;
else      if(gb.display.solid[i].spritecol == houseB1) return true;
else      if(gb.display.solid[i].spritecol == houseB2) return true;
else      if((gb.display.solid[i].spritecol == houseB3) && room == 1) {room = 5; player_y = 32; player_x = 40; camerax = -0; cameray = -40;}
else      if(gb.display.solid[i].spritecol == houseB4) return true;
else      if(gb.display.solid[i].spritecol == houseB5) return true;
else      if(gb.display.solid[i].spritecol == houseT1) return true;
else      if(gb.display.solid[i].spritecol == houseT2) return true;
else      if(gb.display.solid[i].spritecol == houseT3) return true;
else      if(gb.display.solid[i].spritecol == houseT4) return true;
else      if(gb.display.solid[i].spritecol == houseT5) return true;
else      if(gb.display.solid[i].spritecol == roof1) return true;
else      if(gb.display.solid[i].spritecol == roof2) return true;
else      if(gb.display.solid[i].spritecol == roof3) return true;
else      if(gb.display.solid[i].spritecol == roof4) return true;
else      if(gb.display.solid[i].spritecol == roof5) return true;
else      if((gb.display.solid[i].spritecol == bedtop) && gb.buttons.repeat(BTN_A,1)) {gb.popup(F(" ""Aaah! My bed"" "),1); return true;}
else      if(gb.display.solid[i].spritecol == bedtop) return true;
else      if((gb.display.solid[i].spritecol == bedmid) && gb.buttons.repeat(BTN_A,1)) {gb.popup(F(" ""Aaah! My bed"" "),1); return true;}
else      if(gb.display.solid[i].spritecol == bedmid) return true;
else      if((gb.display.solid[i].spritecol == bedbottom) && gb.buttons.repeat(BTN_A,1)) {gb.popup(F(" ""Aaah! My bed"" "),1);}

  
      }
   }
    return false; // Return false if don't touch anything
  }     

The actual switch looks to be in the collision part but i dont really understand what its doing or how.With some help of the members here we straightened out some of the sketch this will go into.But im having trouble deciphering the bits in the cllision that works the switch. im also confused about the camera angle stuff thats with the switches in the collsion. Are these for placing the player in the map when it displays?

here is my code with updated camera controls…


/*This is the Main function file for the GameR-Iot Multiple MCU Arduino driven 
 * game system and DIY console. This is a demo game RPG set in the Dune Universe
 * created by Frank Herbert.
 */
#include <GrafxT3.h>
#include <SPIN.h>
#include "SPI.h"
#include <Bounce.h>
#include "Player.h"
#include "World.h"
#include "Monsters.h"
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#define TFT_DC  9
#define TFT_CS 10
#define TFT_RST 7
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
uint8_t use_fb = 1;
uint8_t use_clip_rect = 0;
uint8_t use_set_origin = 0;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
GrafxT3 tft = GrafxT3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO, &SPIN);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 int player_x = 240;
 int player_y = 320;
 int player_direction = 2;
 int x=-0,y=0;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Camera offset
int cameraX = -160;  /////starting position X 0f camera on tilemap
int cameraY = -120;  /////starting position Y of camera on tilemap

// Camera speed in pixels per update
int cameraXSpeed = 3;
int cameraYSpeed = 3;

// Camera offset boundaries
const int cameraXMin = -2080;
const int cameraXMax = 0;
const int cameraYMin = -2144;
const int cameraYMax = 0;

// Player offset boundaries
const int playerXMin = 80;
const int playerXMax = 240;
const int playerYMin = 80;
const int playerYMax = 160;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////Pixel Color Includes////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
uint16_t palette[16];  // Should probably be 256, but I don't use many colors...
uint16_t pixel_data[2500];

//Extra integers for color palette
int a = 0xa; int b = 0xb; int c = 0xc; 
int d = 0xd; int e = 0xe; int f = 0xf;

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////Button assignments//////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//////dpad + select buttons
const int buttonUp = 33; //up button
Bounce ButtonUp = Bounce(buttonUp, 10);  // 10 ms debounce
const int buttonDown = 38; //down_button
Bounce ButtonDown = Bounce(buttonDown, 10);  // 10 ms debounce
const int buttonLeft = 35; //left button
Bounce ButtonLeft = Bounce(buttonLeft, 10);  // 10 ms debounce
const int buttonRight = 17; //right button
Bounce ButtonRight = Bounce(buttonRight, 10);  // 10 ms debounce
const int buttonS = 21; //select button
Bounce ButtonS = Bounce(buttonS, 10);  // 10 ms debounce

//////action + start buttons
const int buttonX = 32; // X button up
Bounce ButtonX = Bounce(buttonX, 10);  // 10 ms debounce
const int buttonY = 26; // Y button left
Bounce ButtonY = Bounce(buttonY, 10);  // 10 ms debounce
const int buttonA = 21; // A button right
Bounce ButtonA = Bounce(buttonA, 10);  // 10 ms debounce
const int buttonB = 28; // B buttun down
Bounce ButtonB = Bounce(buttonB, 10);  // 10 ms debounce
const int buttonT = 4; // Start button
Bounce ButtonT = Bounce(buttonT, 10);  // 10 ms debounce

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////Set-up//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void setup() {
  while (!Serial && (millis() < 4000)) ;
  Serial.begin(115200);
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  //tft.setFrameRate(60);
  tft.persistence = false;
   pinMode(buttonUp, INPUT_PULLUP);
   pinMode(buttonDown, INPUT_PULLUP);
   pinMode(buttonLeft, INPUT_PULLUP);
   pinMode(buttonRight, INPUT_PULLUP);
   pinMode(buttonS, INPUT_PULLUP);
   pinMode(buttonX, INPUT_PULLUP);
   pinMode(buttonY, INPUT_PULLUP);
   pinMode(buttonA, INPUT_PULLUP);
   pinMode(buttonB, INPUT_PULLUP);
   pinMode(buttonT, INPUT_PULLUP); 
 
   tft.useFrameBuffer(use_fb);
     uint32_t start_time = millis(); 
//       use_fb = !use_fb;
 
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////Loop////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void loop(void) {
   //updates the GameRIot (the display, the sound, the buttons, everyyhing)
  //returns true when it's time to render a new frame (20 times/second)
//   if(tft.updateAll()){

///////////////////////////////////////////////////////////////////////////////
////////////////////////////////camera controls////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Clamp cameraX
if(cameraX < cameraXMin)
{
  cameraX = cameraXMin;
}
else if(cameraX > cameraXMax)
{
   cameraX = cameraXMax;
}

// Clamp cameraY
if(cameraY < cameraYMin)
{
  cameraY = cameraYMin;
}
else if(cameraY > cameraYMax)
{
   cameraY = cameraYMax;  
}

// Check if player is beyond X boundary
if(player_x < playerXMin)
{
  cameraX += cameraXSpeed;
  if(cameraX > cameraXMin && cameraX < cameraXMax)
  {
    player_x = playerXMin;
  }
}
else if(player_x > playerXMax)
{
  cameraX -= cameraXSpeed;
  if(cameraX > cameraXMin && cameraX < cameraXMax)
  {
    player_x = playerXMax;
  }
}

// Check if player is beyond Y boundary
if(player_y < playerYMin)
{
  cameraY += cameraYSpeed;
  if(cameraY > cameraYMin && cameraY < cameraYMax)
  {
    player_y = playerYMin;
  }
}
else if(player_y > playerYMax)
{
  cameraY -= cameraYSpeed;
  if(cameraY > cameraYMin && cameraY < cameraYMax)
  {
    player_y = playerYMax;
  }
}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Palette////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 palette[0] = 0;
       palette[1] = BLACK;
             palette[2] = BLUE;
                   palette[3] = BROWN;
                         palette[4] = DARKGREEN;
                              palette[5] = GREY;
                                    palette[6] = PINK;
                                          palette[7] = RED;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////                                                
                                           palette[8] = LIGHTBROWN;
                                     palette[9] = GREEN;
                               palette[a]= DARKGREY;
                         palette[b] = LIGHTGREY;
                   palette[c] = YELLOW; 
             palette[d] = PURPLE; 
       palette[e] = WHITE;
 palette[f] = NAVY;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////Tilemap/////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

tft.drawTilemap(cameraX, cameraY, dune_demo, spritesheet, palette);
 
///////////////////////////////////////////////////////////////////////////////
///////////////////////////Buttons/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////  
       if (ButtonUp.update());
               if (ButtonDown.update());
                       if (ButtonLeft.update());
                             if (ButtonRight.update());
                                       if (ButtonA.update());
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
                                       ButtonUp.rebounce(10);
                               ButtonDown.rebounce(10);
                       ButtonLeft.rebounce(10);
            ButtonRight.rebounce(10);
     ButtonA.rebounce(10);
///////////////////////////////////////////////////////////////////////////////
////////////////////////////Up/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 if (ButtonUp.fallingEdge()){
     tft.writeRectNBPP(player_x, player_y,16,16,4,paulrearw,palette);
     player_direction = 1;
     player_y -= 3;
     if(checkcolision())
     {
      player_y += 3;} 
     }
     if(player_y <= 32){
        player_y = 32;}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Down///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 if (ButtonDown.fallingEdge()){
   tft.writeRectNBPP(player_x, player_y,16,16,4,paulfrontw,palette);
   player_direction = 2;
   player_y += 3;
    if(checkcolision())
    {
    player_y -=3;}
    }
    if(player_y >= 216){
       player_y = 216;}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////Left////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 if (ButtonLeft.fallingEdge()){
   tft.writeRectNBPP(player_x, player_y,16,16,4,paulleftw,palette);
   player_direction = 3;
   player_x -= 3;
   if(checkcolision())
   {
      player_x += 3;}  
   }
   if(player_x >= 288){
      player_x = 288;}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////Right////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (ButtonRight.fallingEdge()){
  tft.writeRectNBPP(player_x, player_y,16,16,4,paulrightw,palette);
  player_direction = 4;
  player_x += 3;
  if(checkcolision())
  {
    player_x -= 3;}
  }
            if(player_x <= 32){
              player_x = 32;}
///////////////////////////////////////////////////////////////////////////////     
//////////////////////////////PLAYER DIRECTION/////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (player_direction == 1){
  tft.writeRectNBPP(player_x, player_y,16,16,4,paulrear,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 2){
   tft.writeRectNBPP(player_x, player_y,16,16,4,paulfront,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 3){
    tft.writeRectNBPP(player_x, player_y,16,16,4,paulleft,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 4){
     tft.writeRectNBPP(player_x, player_y,16,16,4,paulright,palette);
        }
       tft.updateScreen(); 
     }
//}
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////collision/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
bool checkcolision(void) // Transformed it into a function 
{
  for(uint16_t i=0; i < tft.numcolision + 1; i++)
  {
    if(tft.collideRectRect(player_x, player_y,16,16,tft.solid[i].x,tft.solid[i].y,16,16))
    {
      if(tft.solid[i].spritecol == cave) return true;
      else if(tft.solid[i].spritecol == rock){tft.popup(F(" ""Rock"" "),1); return true;} //Return True if character have touched the wall//return true;
      else if(tft.solid[i].spritecol == rockbl)return true;
      else if(tft.solid[i].spritecol == rockbr)return true;
      else if(tft.solid[i].spritecol == rocktl)return true;
      else if(tft.solid[i].spritecol == rocktr)return true;
      else if(tft.solid[i].spritecol == seitch) return true;
      else if(tft.solid[i].spritecol == stairsl) return true;
      else if(tft.solid[i].spritecol == stairsr) return true;
    }
  }
  return false; // Return false if don't touch anything
}

//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
 

when ever I try this…

[code]
else if(tft.solid[i].spritecol == cave) && room == 1) {room = 2; player_x = 32; player_y = 204; cameraX = 170; cameraY = 110;} //return true;
[/code

I get these errors…

Arduino: 1.8.2 (Windows 7), TD: 1.36, Board: "Teensy 3.6, Serial, 180 MHz, Faster, US English"

Dune_RPG: In function 'void setup()':
Dune_RPG:122: warning: unused variable 'start_time' 
      uint32_t start_time = millis(); 

               ^

Dune_RPG: In function 'void loop()':
Dune_RPG:201: warning: large integer implicitly truncated to unsigned type 
                                     palette[6] = PINK;

                                                ^

Dune_RPG: In function 'bool checkcolision()':
Dune_RPG:323: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
       else if(tft.solid[i].spritecol == cave) && room == 1){room = 2; player_x = 32; player_y = 204; cameraX = 170; cameraY = 110;} //return true;

                                                          ^

Dune_RPG:323: error: expected ';' before ')' token
       else if(tft.solid[i].spritecol == cave) && room == 1){room = 2; player_x = 32; player_y = 204; cameraX = 170; cameraY = 110;} //return true;

                                                           ^

Dune_RPG:323: warning: statement has no effect 
       else if(tft.solid[i].spritecol == cave) && room == 1){room = 2; player_x = 32; player_y = 204; cameraX = 170; cameraY = 110;} //return true;

                                                       ^

Dune_RPG:323: error: label 'room' used but not defined
       else if(tft.solid[i].spritecol == cave) && room == 1){room = 2; player_x = 32; player_y = 204; cameraX = 170; cameraY = 110;} //return true;

                                                  ^

ISO C++ forbids comparison between pointer and integer [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I don’t understand its wriiten just like the code in the first post.

Ok so the problem above was due to a missing parentheses. Looked at it for hours and didn’t see it. But then I did and it works now.

Now I would like to be able to trigger monsters. Then be able to fight them. But I have no idea where to start. I guess I need to do player profiles and monster profiles first so they have fight stats. IDK

How would you proceed?

Ok ive been looking at the code for arduventure and i can see how to do somethings but i cant figure out how the battles are triggered.

Can some one help me please?

Oops wrong thread!

Edit:: when ever i click on the thread for advice on my rpg it just takes me here.

Is this one of those talk to your self and find answers thing?

Well I was hoping for more but it does happen that way sometimes. Ive been looking at the battle.h for arduventure and I understand most of but I don’t really get the battle formation stuff here…

//------------------------
// Battle formations
//------------------------
byte currentBattleFormation, currentEnemyAmount;
byte currentEnemies[4];
int currentEnemyHealth[4];

const unsigned char PROGMEM battleFormation0[] = {3, 0, 1, 0};
const unsigned char PROGMEM battleFormation1[] = {2, 1, 0};
const unsigned char PROGMEM battleFormation2[] = {1, 2};
const unsigned char PROGMEM battleFormation3[] = {4, 0, 0, 0, 0};
const unsigned char PROGMEM battleFormation4[] = {3, 2, 2, 2};

const byte BATTLEFORMATIONAMOUNT = 4;
const unsigned char *battleFormations[] =
{
  battleFormation0, battleFormation1, battleFormation2, battleFormation3, battleFormation4
};

specifically what are the intergers in the {} brackets, and what is the 4 in the {} if there are only 3 actual monsters

heres the whole file

#define BATTLESTATE_ACTIONCHOICE 0
#define BATTLESTATE_ENEMYCHOICE 1
#define BATTLESTATE_PLAYERATTACKING 2
#define BATTLESTATE_ENEMIESDAMAGING 3
#define BATTLESTATE_ENEMIESATTACKING 4
#define BATTLESTATE_PLAYERDAMAGING 5
#define BATTLESTATE_WON 6
#define BATTLESTATE_END 7

byte battleState = BATTLESTATE_ACTIONCHOICE;
byte battleStartEffectCounter = 0;
byte battleStartEffectToggle = false;

byte battleDamageEffectCounter = 0;
byte battleDamageEffectToggle = true;

byte currentActionChoice = 0;
byte currentEnemyChoice = 0;
byte currentEnemyTurn = 0;
byte changedChoice = false;

const unsigned char battleChoices[] =
{
  18,
  0,19,19,0,2,10,NONE,NONE,8,19,4,12,18,NONE,NONE,17,20,13
};

const unsigned char battleChoicePositions[] =
{
  4, 52, 94
};

//------------------------
// Battle formations
//------------------------
byte currentBattleFormation, currentEnemyAmount;
byte currentEnemies[4];
int currentEnemyHealth[4];

const unsigned char PROGMEM battleFormation0[] = {3, 0, 1, 0};
const unsigned char PROGMEM battleFormation1[] = {2, 1, 0};
const unsigned char PROGMEM battleFormation2[] = {1, 2};
const unsigned char PROGMEM battleFormation3[] = {4, 0, 0, 0, 0};
const unsigned char PROGMEM battleFormation4[] = {3, 2, 2, 2};

const byte BATTLEFORMATIONAMOUNT = 4;
const unsigned char *battleFormations[] =
{
  battleFormation0, battleFormation1, battleFormation2, battleFormation3, battleFormation4
};

//------------------------
// Enemies
//------------------------

// Struct
struct Enemy
{
    int id, health, attack, defense, speed, exp, gold;
};

const byte ENEMYAMOUNT = 3;
const Enemy enemies[] =
{
  {0, 7, 5, 0, 1, 5, 2}, // Worm
  {1, 10, 7, 1, 1, 8, 8}, // Beetle
  {2, 12, 8, 3, 1, 15, 15}  // Bird
};

// Bitmaps
const unsigned char PROGMEM enemyBitmaps[][32] =
{
  {0x00,0x00,0x00,0xf8,0xa4,0x82,0xa2,0x92,0x04,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x34,0x64,0x64,0x72,0x6f,0x38,0x38,0x1c,0x0c,0x00,0x00},
  {0x00,0xe0,0x98,0x44,0x32,0x2a,0x21,0x21,0x31,0x49,0x82,0x02,0xc4,0xe8,0x70,0x80,0xee,0x99,0x6f,0x1c,0x25,0x3a,0x18,0x3a,0x25,0x1c,0x6f,0x9f,0xe7,0x0d,0x13,0x1d},
  {0xc0,0x20,0x1c,0x12,0xa1,0xd1,0x89,0x09,0x02,0x3c,0x50,0x48,0x5c,0x44,0x78,0xc0,0x01,0xc2,0xa4,0xdf,0xba,0xf1,0x70,0xf0,0xba,0xdc,0x98,0xb8,0x58,0x09,0x05,0x03},
};

// Names
const unsigned char name0[] = {4, 22,14,17,12};
const unsigned char name1[] = {6, 1,4,4,19,11,4};
const unsigned char name2[] = {4, 1,8,17,3};


const unsigned char *enemyNames[] =
{
  name0, name1, name2
};

const unsigned char labelHealth[] = {3, 7,15,41};

Why not
Rect rectA{x,y,x,y};
Rect recB {ply-x,ply-y,16,16};
If(count == 0)
{
x = random(0,120);
y = random(0,64);
Count = 1;
}
If(arduboy.collide( rectA,rectB))
{
Do something
}

well that’s simple. What about the integers in the {} for battleformations()

The implementation is in the main file here:

void startBattle()
{
  battleStartEffectCounter = 40;
  battleState = BATTLESTATE_ACTIONCHOICE;
  currentActionChoice = 0;
  currentEnemyChoice = 0;

  currentBattleFormation = generateRandomNumber(BATTLEFORMATIONAMOUNT);
  currentEnemyAmount = pgm_read_byte(&battleFormations[currentBattleFormation][0]);
  
  for(byte i = 0; i < 4; i++)
  {
    currentEnemyHealth[i] = (i < currentEnemyAmount)?enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].health:0;
    currentEnemies[i] = (i < currentEnemyAmount)?enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].id:0;
  }
}

Any clues as to the integers in the {} after each battle formation? At first i thought they were for each monster but integers are listed 0 through 4.

Post 7

Did you attempt to read the startBattle function at all?

Ok I’ve been looking at the start battle function but I cant see where it’s telling me what the integers are for this part in code…


//------------------------
// Battle formations
//------------------------
byte currentBattleFormation, currentEnemyAmount;
byte currentEnemies[3];
int currentEnemyHealth[4];

const unsigned char PROGMEM battleFormation0[] = {3, 0, 1, 0};  ////////these
const unsigned char PROGMEM battleFormation1[] = {2, 1, 0};      ////////these
const unsigned char PROGMEM battleFormation2[] = {1, 2};          ///////these
const unsigned char PROGMEM battleFormation3[] = {4, 0, 0, 0, 0};  ////////these
const unsigned char PROGMEM battleFormation4[] = {3, 2, 2, 2};     /////////these

const byte BATTLEFORMATIONAMOUNT = 4;
const unsigned char *battleFormations[] =
{
  battleFormation0, battleFormation1, battleFormation2, battleFormation3, battleFormation4
};

It uses 5 different integers total in the brackets but there are only 3 monsters. So what do integers 3 and 4 represent? Really all of them.

plus I only want 3 monsters per formation

The startBattle function explains what they do.

currentBattleFormation = generateRandomNumber(BATTLEFORMATIONAMOUNT);
  currentEnemyAmount = pgm_read_byte(&battleFormations[currentBattleFormation][0]);
  
  for(byte i = 0; i < 4; i++)
  {
    currentEnemyHealth[i] = (i < currentEnemyAmount)?enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].health:0;
    currentEnemies[i] = (i < currentEnemyAmount)?enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].id:0;
  }

ok well im just not understanding it. Can we pretend im stiil learning? Would you mind helping me understand please? pretty please?

currentBattleFormation = generateRandomNumber(BATTLEFORMATIONAMOUNT);

Generates a random number between 0 and 4. This is an index to the array of battleFormations.

currentEnemyAmount = pgm_read_byte(&battleFormations[currentBattleFormation][0]);

Works out how many enemies in the selected formation. It is the first number in each array. Note the first array {3,0,1,0} has three enemies and the subsequent data points to enemy types declared in the enemies[] array. Four appears to be the maximum number of enemies.

for(byte i = 0; i < 4; i++) {

Loop through the enemies (up to four) …

currentEnemyHealth[i] = (i < currentEnemyAmount) ?enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].health : 0;

There is an array declared at the top of the code called currentEnemyHealth which has five elements numbered 0 to 4. The battle formation values are indexes that refer to the enemies array which is declared somewhere else. It uses the various indexes (0, 1 or 2) to pick an enemy type and retrieve its health value and populates the currentEnemyHealth array with the retrieved health value.

currentEnemies[i] = (i < currentEnemyAmount) ? enemies[pgm_read_byte(&battleFormations[currentBattleFormation][i + 1])].id : 0;

This does the same thing as the line above but retrieves the id of the enemy. The currentEnemies array is four elements long (indexes 0 to 3) which makes sense as you can only have four enemies. Again, not sure why the currentEnemyHealth array is five elements - could be a simple typo or maybe the fifth is used for something else?

1 Like

It could be future proofing for when they support 5 enemies or it could be a simple mistake. I wouldn’t have thought it was being used for something else (at least I hope it isn’t) but I can’t be bothered to read all the code to find out.


If you’re just handed the answer you’ll find learning harder in the long run.
Besides which it’s a lot easier to help someone when you know exactly which parts they are struggling with, so far you you’ve asked a lot of questions but haven’t really given much indication of how much you do or don’t understand.

For example, if it was the pgm_read_byte part you were struggling with I’d give an explanation of progmem and how pgm_read_byte is used to read bytes from arrays in progmem.
If the part inside the loop was what you were struggling with, I’d explain the ins and outs of th ternary operator.
If it was the .health and .id parts I’d be explaining structs and how they work and are accessed.

Thanks guys!!! That totally helps a lot!!

I get the structure parts where they list variables such as enemy health, id, etc. I just couldn’t see how the start command was connected connected to the battle formations but now I do. Sorry I know I can be dense. I appreciate any explanations I can get.

Im at the bitmaps now. Here…

const unsigned char PROGMEM enemyBitmaps[][32] =
{
  {0x00,0x00,0x00,0xf8,0xa4,0x82,0xa2,0x92,0x04,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x34,0x64,0x64,0x72,0x6f,0x38,0x38,0x1c,0x0c,0x00,0x00},
  {0x00,0xe0,0x98,0x44,0x32,0x2a,0x21,0x21,0x31,0x49,0x82,0x02,0xc4,0xe8,0x70,0x80,0xee,0x99,0x6f,0x1c,0x25,0x3a,0x18,0x3a,0x25,0x1c,0x6f,0x9f,0xe7,0x0d,0x13,0x1d},
  {0xc0,0x20,0x1c,0x12,0xa1,0xd1,0x89,0x09,0x02,0x3c,0x50,0x48,0x5c,0x44,0x78,0xc0,0x01,0xc2,0xa4,0xdf,0xba,0xf1,0x70,0xf0,0xba,0xdc,0x98,0xb8,0x58,0x09,0x05,0x03},
};

// Names
const unsigned char name0[] = {4, 22,14,17,12};
const unsigned char name1[] = {6, 1,4,4,19,11,4};
const unsigned char name2[] = {4, 1,8,17,3};


const unsigned char *enemyNames[] =
{
  name0, name1, name2
};

the first part is the number [32] after enemy bitmaps. the bitmaps are 16x16 and there are 3 so that doesn’t quite add up to 32.

the second is the name part. At first I thought the variables were spelling the names using the number of a particular font character in the font array but that doesn’t sync right.

Now heres the big question… My bitmap monsters are all different sizes from small to big to large. The draw enemy bitmap function in draw battle uses the size 16,16, since all the enemy bitmaps are 16x16. is there a way to add a variable that kills the standard size info in the function and makes it so it can display bitmaps of different sizes?

There is 1 bit per bitmap

16 * 16 = 256 bits

and 8 bits per char.

256 / 8 = 32 chars

As ever my favourite image explaining the Arduboy image format is the one @emutyworks made last year:

That’s exactly what they’re doing.
Don’t ask me which number corresponds to what letter though, I have no clue.

On the Arduboy you can choose the size of the bitmap you want to draw.
On the hardware you’re using I have no idea what the protocol would be.
I expect it’s possible, but I’m not well versed with your library/hardware, so that would be a better question for someone who is.

That example is so weird!!! I think I can make my own font array. You wouldn’t know what number corresponds to what letter with out a copy of the array in visual format. I looked at it again and I can see it better but im curios as to what the first number corresponds too.

Ok lets talk bitmap. The bitmap functions call size the same way they all do. like this…

 void        drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);

the only diffrences are the order that the variables are called and it gets a color variable. Im using something a lil different but it works on the same principal. We just add the bit per pixel amount and the uint16_t color becomes palette.

ok so heres what I meant in my last post. First lets look at the drawbattle function…

void drawBattle()
{
  arduboy.fillRect(0, 10, 128, 36, WHITE); ////////background stripe for monsters to sit on top of width of total screen res

  for(int i = 0; i < currentEnemyAmount; i++)
  {
    byte xPos = ((128 - (currentEnemyAmount * 16) - ((currentEnemyAmount - 1) * 4)) / 2) + (i * 20);
    if(currentEnemyHealth[i] != 0)
    {
      if(battleState == BATTLESTATE_ENEMYCHOICE && i == currentEnemyChoice) arduboy.drawBitmap(xPos + 5, 20, font[45], 5, 5, BLACK);  ////////////// don't know what this does
      
      if(battleState == BATTLESTATE_ENEMIESDAMAGING && i == currentEnemyChoice && !battleDamageEffectToggle) continue;
      else arduboy.drawBitmap(xPos, (battleState == BATTLESTATE_PLAYERDAMAGING && i == currentEnemyTurn)?22:26, enemyBitmaps[currentEnemies[i]], 16, 16, BLACK); ///////////// actually calls enemies to the screen
    }
  }

  arduboy.drawBitmap(battleChoicePositions[currentActionChoice], 50, font[43], 5, 5, WHITE); //// don't know this
  drawText(battleChoices, 10, 50, WHITE, ALIGN_LEFT);
  
  drawText(labelHealth, 4, 2, WHITE, ALIGN_LEFT);
  drawHealth(22, 2, WHITE);

  if(battleState == BATTLESTATE_ENEMYCHOICE)
  {
    drawText(enemyNames[currentEnemies[currentEnemyChoice]], 4, 14, BLACK, ALIGN_LEFT);
  }
}

ok first which one calls the monsters to be drawn on screen? I think its battle state enemy choice but the size variable is only 5 x 5. Battle state enemies damaging on the other hand does calls a 16x16 bitmap.

IF battlestate enemies damaging is the function calling the monster bitmaps, could it be written In a way that its not stuck on calling bit maps of 16x16, but can also call bitmaps of 40x48, and 32x32, and 34x36 and so on.