seperate sketches for seperate game aspects

Understanding the language, error messages, etc.

seperate sketches for seperate game aspects

Postby Duhjoker » Thu Aug 18, 2016 5:19 am

I didn't really know how to ask this question in the topic so I hope its legible.

ok so im building a pretty massive game for this system and as such trying to compile everything in one sketch sheet can make things a lil crazy as far as debugging goes. Sooooooo

I want to split all the different aspects, worldmap, player, monsters, etc, into separate sketches, and since im still new to all this I need just a lil help.

I started off by pulling all the player sprites off my main then transferring all their controls over too. I removed the display tile map command and placed it in the sketch with just the terrain sprites. but I do not know how to start the map sketch off, do I need to do a void drawmap() then start the gb.display or what.

heres my player code ... I cant figure out why I had to add a curly bracket before void set up and cant find its match but it quit giving me errors after I added it.
Code: Select all


Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

const byte sever_front_black[] PROGMEM = {8,8,0x39,0x7d,0x01,0x01,0xfe,0x01,0x7c,0x46};
const byte sever_front_grey[] PROGMEM = {8,8,0x82,0x82,0xd6,0x7c,0x01,0xa8,0x00,0x00,};
const byte sever_left_black[] PROGMEM = {8,8,0x9f,0xbe,0x80,0x82,0x7f,0x00,0x3e,0x62,};
const byte sever_left_grey[] PROGMEM = {8,8,0x00,0x00,0x17,0x3c,0x00,0x95,0x00,0x00,};
const byte sever_rear_black[] PROGMEM = {8,8,0x9c,0xbe,0xbe,0x80,0x7f,0x88,0x3e,0x62,};
const byte sever_rear_grey[] PROGMEM = {8,8,0x41,0x41,0x7f,0x3e,0x80,0x15,0x00,0x00,};
const byte sever_right_black[] PROGMEM = {8,8,0xf9,0x7d,0x01,0x41,0xfe,0x00,0x7c,0x46,};
const byte sever_right_grey[] PROGMEM = {8,8,0x00,0x00,0xe8,0x3c,0x00,0xa9,0x00,0x00,};

  int player_x = 70;
  int player_y = 40;
  int player_direction = 0;

int x=0,y=0;

int camerax = -20 ;
int cameray = -10 ;
int xmax = -68;
{/////////// do not understand why I had to add this for it to compile,cant find end
void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.setFrameRate(62);
  gb.display.persistence = false;
}

/////////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++;}
     
//////camera controls
if(player_x > 59 && camerax <  0 && camerax  > -52){player_x = 59;camerax--;}   
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camera boundary positions
else  if(player_x < 15 && camerax <  0 && camerax  > -52){player_x = 15;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
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--;}
//value 28 equals player position on right when camera will start to follow
//value 0 and -40 equals camera boundary positions
else  if(player_y < 15 && cameray < 0 && cameray >  -40){player_y = 15;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
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;
//value 0 and -52 equals camera boundary positions
      if(cameray > 0)cameray= 0;   
else  if(cameray < -40) cameray = -40;
//value 0 and -40 equals camera boundary positions
 
 
     

 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_black);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
    }
      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,sever_front_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_grey);
    }
      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,sever_right_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_grey);
    }
      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,sever_left_black);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_grey);
    }
      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,sever_rear_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
        }
 }
     
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_grey);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_grey);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
}
 
}
     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))
    {
 if(gb.display.solid[i].spritecol == void_tile);
          if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == sand);
         if(gb.display.solid[i].spritecol == steps );
else     if(gb.display.solid[i].spritecol == bush)return true;
else     if(gb.display.solid[i].spritecol == dead_tree)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_top)return true;
else     if(gb.display.solid[i].spritecol == dungeon_middle)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_top)return true;
else     if(gb.display.solid[i].spritecol == grave_marker)return true;
else      if(gb.display.solid[i].spritecol == port_noir)return true;
else      if(gb.display.solid[i].spritecol == rock_terrain_master)return true;//{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;

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


heres a shortened version of the map file since the whole thing wont fit.......

Code: Select all

[code]
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

const byte room_1_1[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,13,20,20,20,20,3,20,20,3,20,20,20,20,20,20,20,20,
11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,20,3,20,20,3,20,20,20,20,20,20,
11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte bridge_h[] PROGMEM = {B01110111,B10001000,B10101010,B10001000,B10001000,B10101010,B10001000,B01110111,};
const byte bridge_v[] PROGMEM = {B01111110,B10000001,B10100101,B10000001,B01111110,B10000001,B10100101,B10000001,};
const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte dead_tree[] PROGMEM = {B10101001,B01010110,B01001001,B10101010,B01011010,B00111100,B00011000,B00011000,};
const byte dungeon_left_bottom[] = {B11111111,B10001111,B01001111,B11111111,B10001111,B01001111,B11111111,B10001111,};
const byte dungeon_left_top[] = {B00010001,B00101110,B00101010,B00101110,B01000000,B01000001,B10010010,B10001000,};
const byte dungeon_middle[] = {B10000001,B01000010,B00111100,B00000000,B00000000,B10011001,B00011000,B01000010,};
const byte dungeon_right_bottom[] = {B11111111,B11110001,B11110010,B11111111,B11110001,B11110010,B11111111,B11110001,};
const byte dungeon_right_top[] = {B10001000,B01110100,B01010100,B01110100,B00000010,B10000010,B01001001,B00010001,};
const byte grave_marker[] PROGMEM = {B00011000,B00111100,B01100110,B0100010,B01100110,B01100110,B00111100,B11111111,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B01001101,B10100100,B10010001,B01001010,B10010000,B01100101,B10001001,B01011010,};
const byte rock_valley_ne[] PROGMEM = {B10101010,B10010101,B01000100,B00101001,B00110010,B00001010,B00000100,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B01010101,B10101001,B00100010,B10010100,B01001100,B01010000,B00100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000100,B0011001,B00010010,B00101001,B01000110,B10110001,B10001010,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B00100000,B10011000,B01001000,B10010100,B01100010,B10001101,B01010001,};
const byte sand[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte statue[] PROGMEM = {B10111010,B11000110,B01101100,B11101110,B11111110,B11111110,B01101100,B01101100,};
const byte steps[] PROGMEM = {B01111110,B10000001,B00000000,B10000001,B01111110,B10000001,B00000000,B10000001,};
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 *spritesheet[] = {bridge_h, bridge_v, bush, dead_tree, dungeon_left_bottom, dungeon_left_top, dungeon_middle,
dungeon_right_bottom, dungeon_right_top, grave_marker, port_noir, rock_terrain_master, rock_valley_ne, rock_valley_nw,
rock_valley_se, rock_valley_sw, sand, statue, steps, turtle_rock, void_tile, water_left_bottom, water_left_middle, water_left_top,
water_middle_bottom, water_middle_middle, water_middle_top, water_right_bottom, water_right_middle, water_right_top};

/////don't know what kind of loop to use or how to set up with player sketch
gb.display.drawTilemap(camerax,cameray,room_1_1,spritesheet);










[/code]




User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Thu Aug 18, 2016 6:54 am

OK I gave it my best shot. I got it to compile but its not showing the tilemap, on the other hand the player sprite seems to work, it shows up moves and changes and holds direction. so that means I have done the map sketch wrong. im sure its my loop but cant find what to use.

I removed the camera and collision controls from the player sketch above and added them to the map sketch below, condensed for forum.......

Code: Select all
const byte room_1_1[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,13,20,20,20,20,3,20,20,3,20,20,20,20,20,20,20,20,
11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,20,3,20,20,3,20,20,20,20,20,20,
11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_2[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,20,20,20,11,11,11,11,
11,11,11,13,12,11,11,11,11,11,20,20,20,12,11,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,13,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_3[] PROGMEM = {17,11,
8,8,
2,2,2,2,2,2,20,20,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,20,20,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
20,20,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
20,20,20,20,20,20,2,2,2,2,2,2,2,2,2,2,
20,20,20,20,20,20,2,2,2,2,2,2,2,2,2,2,
2,2,20,20,20,20,2,2,2,2,2,2,2,2,2,2,2,
2,2,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
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,};

const byte room_1_4[] PROGMEM = {17,11,
8,8,
2,2,2,2,2,2,2,20,20,20,2,20,2,2,20,2,2,
2,2,2,2,2,2,2,20,20,20,2,20,2,2,20,2,2,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,2,2,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,2,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,2,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,2,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,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,};

const byte room_1_5[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,13,20,20,20,20,20,20,12,11,11,13,20,20,20,12,11,
13,20,20,20,20,20,20,20,20,12,13,20,20,20,20,20,11,
20,20,20,20,2,20,20,20,20,20,20,20,2,20,20,20,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,
20,20,20,20,2,20,20,20,20,20,20,20,2,20,20,20,11,
15,20,20,20,20,20,20,20,20,14,1,520,20,20,20,20,11,
11,15,20,20,20,20,20,20,24,22,22,25,20,20,20,14,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_6[] PROGMEM = {17,11,
8,8,
11,11,11,11,20,22,28,11,11,11,11,11,11,11,11,11,11,
11,11,10,11,20,22,28,12,11,11,11,11,11,11,11,11,11,
11,13,20,20,20,22,28,20,20,20,20,20,20,20,20,20,20,
11,20,20,20,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,19,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,19,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,20,20,22,28,20,20,20,19,20,20,20,20,20,20,
11,20,20,20,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,15,20,20,20,22,28,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,15,22,28,14,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,22,28,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_7[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,13,20,20,20,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,11,
20,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,12,
20,20,19,20,20,19,20,20,19,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,14,
20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,14,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};


const byte room_1_8[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,11,10,13,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,11,13,20,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,13,20,20,20,20,20,11,11,11,11,11,11,11,
11,11,11,13,20,20,20,20,20,20,11,11,11,11,11,11,11,
11,11,13,20,20,20,20,20,20,20,11,11,11,11,11,11,11,
11,13,20,20,20,20,20,20,20,20,12,11,11,11,11,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_9[] PROGMEM = {17,11,
8,8,
11,11,2,20,2,20,2,20,20,20,2,20,2,20,2,20,2,
11,11,2,20,2,20,2,20,20,20,2,20,2,20,2,20,2,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,13,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
20,20,2,20,2,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
20,20,2,20,2,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
11,11,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,};

const byte bridge_h[] PROGMEM = {B01110111,B10001000,B10101010,B10001000,B10001000,B10101010,B10001000,B01110111,};
const byte bridge_v[] PROGMEM = {B01111110,B10000001,B10100101,B10000001,B01111110,B10000001,B10100101,B10000001,};
const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte dead_tree[] PROGMEM = {B10101001,B01010110,B01001001,B10101010,B01011010,B00111100,B00011000,B00011000,};
const byte dungeon_left_bottom[] = {B11111111,B10001111,B01001111,B11111111,B10001111,B01001111,B11111111,B10001111,};
const byte dungeon_left_top[] = {B00010001,B00101110,B00101010,B00101110,B01000000,B01000001,B10010010,B10001000,};
const byte dungeon_middle[] = {B10000001,B01000010,B00111100,B00000000,B00000000,B10011001,B00011000,B01000010,};
const byte dungeon_right_bottom[] = {B11111111,B11110001,B11110010,B11111111,B11110001,B11110010,B11111111,B11110001,};
const byte dungeon_right_top[] = {B10001000,B01110100,B01010100,B01110100,B00000010,B10000010,B01001001,B00010001,};
const byte grave_marker[] PROGMEM = {B00011000,B00111100,B01100110,B0100010,B01100110,B01100110,B00111100,B11111111,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B01001101,B10100100,B10010001,B01001010,B10010000,B01100101,B10001001,B01011010,};
const byte rock_valley_ne[] PROGMEM = {B10101010,B10010101,B01000100,B00101001,B00110010,B00001010,B00000100,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B01010101,B10101001,B00100010,B10010100,B01001100,B01010000,B00100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000100,B0011001,B00010010,B00101001,B01000110,B10110001,B10001010,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B00100000,B10011000,B01001000,B10010100,B01100010,B10001101,B01010001,};
const byte sand[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte statue[] PROGMEM = {B10111010,B11000110,B01101100,B11101110,B11111110,B11111110,B01101100,B01101100,};
const byte steps[] PROGMEM = {B01111110,B10000001,B00000000,B10000001,B01111110,B10000001,B00000000,B10000001,};
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 *spritesheet[] = {bridge_h, bridge_v, bush, dead_tree, dungeon_left_bottom, dungeon_left_top, dungeon_middle,
dungeon_right_bottom, dungeon_right_top, grave_marker, port_noir, rock_terrain_master, rock_valley_ne, rock_valley_nw,
rock_valley_se, rock_valley_sw, sand, statue, steps, turtle_rock, void_tile, water_left_bottom, water_left_middle, water_left_top,
water_middle_bottom, water_middle_middle, water_middle_top, water_right_bottom, water_right_middle, water_right_top};


int camerax = -20 ;
int cameray = -10 ;
int xmax = -68;


void drawTileMap(){
 gb.begin();
gb.display.drawTilemap(camerax,cameray,room_1_9,spritesheet);
//////camera controls
if(player_x > 59 && camerax <  0 && camerax  > -52){player_x = 59;camerax--;}   
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camera boundary positions
else  if(player_x < 15 && camerax <  0 && camerax  > -52){player_x = 15;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
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--;}
//value 28 equals player position on right when camera will start to follow
//value 0 and -40 equals camera boundary positions
else  if(player_y < 15 && cameray < 0 && cameray >  -40){player_y = 15;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
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;
//value 0 and -52 equals camera boundary positions
      if(cameray > 0)cameray= 0;   
else  if(cameray < -40) cameray = -40;
//value 0 and -40 equals camera boundary positions
}

  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))
    {
 if(gb.display.solid[i].spritecol == void_tile);
          if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == sand);
         if(gb.display.solid[i].spritecol == steps );
else     if(gb.display.solid[i].spritecol == bush)return true;
else     if(gb.display.solid[i].spritecol == dead_tree)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_top)return true;
else     if(gb.display.solid[i].spritecol == dungeon_middle)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_top)return true;
else     if(gb.display.solid[i].spritecol == grave_marker)return true;
else      if(gb.display.solid[i].spritecol == port_noir)return true;
else      if(gb.display.solid[i].spritecol == rock_terrain_master)return true;//{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;

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




User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Thu Aug 18, 2016 9:09 am

ok after looking at few reference materials I renamed the tilemap loop void drawTileMap() and the player loop on its sketch as void move_player then added a third sketch like this..... it compiles but shows nothing.

Code: Select all
void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.setFrameRate(62);
  gb.display.persistence = false;
}

void loop(){
  if(gb.update()){
    drawTileMap();
    move_player();
  }
}


player sketch that matches tile map sketch above......
Code: Select all
#include <SPI.h>
#include <Gamebuino.h>

Gamebuino gb;

const byte sever_front_black[] PROGMEM = {8,8,0x39,0x7d,0x01,0x01,0xfe,0x01,0x7c,0x46};
const byte sever_front_grey[] PROGMEM = {8,8,0x82,0x82,0xd6,0x7c,0x01,0xa8,0x00,0x00,};
const byte sever_left_black[] PROGMEM = {8,8,0x9f,0xbe,0x80,0x82,0x7f,0x00,0x3e,0x62,};
const byte sever_left_grey[] PROGMEM = {8,8,0x00,0x00,0x17,0x3c,0x00,0x95,0x00,0x00,};
const byte sever_rear_black[] PROGMEM = {8,8,0x9c,0xbe,0xbe,0x80,0x7f,0x88,0x3e,0x62,};
const byte sever_rear_grey[] PROGMEM = {8,8,0x41,0x41,0x7f,0x3e,0x80,0x15,0x00,0x00,};
const byte sever_right_black[] PROGMEM = {8,8,0xf9,0x7d,0x01,0x41,0xfe,0x00,0x7c,0x46,};
const byte sever_right_grey[] PROGMEM = {8,8,0x00,0x00,0xe8,0x3c,0x00,0xa9,0x00,0x00,};

int player_x = 70;
int player_y = 40;
int player_direction = 0;

int x=0,y=0;



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

void move_player() {
  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(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_black);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
    }
      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,sever_front_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_grey);
    }
      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,sever_right_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_grey);
    }
      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,sever_left_black);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_grey);
    }
      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,sever_rear_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
        }
 }
     
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_grey);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_grey);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
}
 
}
   
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Sorunome » Thu Aug 18, 2016 9:30 am

You make multiple .ino files in the same folder. The .ino file with the same name as the folder is called is your main file, it's the thing that requires the setup() and the loop() functions.

However, to be able to "use" variables from another file you have to do something like `external const byte *gamemaps[];` at the beginning of your file (example here, the other file is here. Note how I don't need to add external things for all the individual gamemaps, as those technically aren't used in the other file, i only access *gamemaps[])

I hope this answers your question :)
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Fri Aug 19, 2016 6:56 am

Ok so I have my Esmerelda.ino that has the void setup and loop and void loop on it and a player.ino file and a map.ino file. The player file has all the player sprites and movements the map file has the code to display the maps plus the camera controls.

So on my Esmerelda.ino file I need to add extern const byte for map Sprite[] sheet then one for each of my sever sprites? All this before my void setup and void loop?
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Sorunome » Fri Aug 19, 2016 8:04 am

If you use a spritesheet you only need to add that one. Yess, all on the top before setup() and loop()
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Fri Aug 19, 2016 8:46 am

I don't think I can use a Sprite sheet for the sever sprites.

Can the voids for my player on its sketch and the voids on the map sketches be called anything or is it better to use a specific set of words for each one.

Like my player void on its sketch is simply named void player_movement()
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Sat Aug 20, 2016 5:36 am

ok ive been working and I got everything tom compile but when I simbuino it, I get blank screen except for the battery.........
/////// esmerelda.ino
Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

extern const byte *spritesheet[];

extern const byte sever_front_black[];
extern const byte sever_front_grey[];
extern const byte sever_left_black[];
extern const byte sever_left_grey[];
extern const byte sever_rear_black[];
extern const byte sever_rear_grey[];
extern const byte sever_right_black[];
extern const byte sever_right_grey[];



void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.setFrameRate(62);
  gb.display.persistence = false;
}

void loop(){
  if(gb.update()){
    drawTileMap();
    move_player();
  }
}


/////////map.ino
Code: Select all
int player_x = 70;
int player_y = 40;
int player_direction = 0;

int x=0,y=0;


/////////////map controls/////////////



const byte room_1_1[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,13,20,20,20,20,3,20,20,3,20,20,20,20,20,20,20,20,
11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,20,3,20,20,3,20,20,20,20,20,20,
11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_2[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,20,20,20,11,11,11,11,
11,11,11,13,12,11,11,11,11,11,20,20,20,12,11,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,13,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_3[] PROGMEM = {17,11,
8,8,
2,2,2,2,2,2,20,20,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,20,20,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
20,20,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
20,20,20,20,20,20,2,2,2,2,2,2,2,2,2,2,
20,20,20,20,20,20,2,2,2,2,2,2,2,2,2,2,
2,2,20,20,20,20,2,2,2,2,2,2,2,2,2,2,2,
2,2,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
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,};

const byte room_1_4[] PROGMEM = {17,11,
8,8,
2,2,2,2,2,2,2,20,20,20,2,20,2,2,20,2,2,
2,2,2,2,2,2,2,20,20,20,2,20,2,2,20,2,2,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,2,2,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,2,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,2,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,20,
2,2,2,2,2,2,2,20,20,20,20,20,20,20,20,20,2,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,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,};

const byte room_1_5[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,13,20,20,20,20,20,20,12,11,11,13,20,20,20,12,11,
13,20,20,20,20,20,20,20,20,12,13,20,20,20,20,20,11,
20,20,20,20,2,20,20,20,20,20,20,20,2,20,20,20,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,
20,20,20,20,2,20,20,20,20,20,20,20,2,20,20,20,11,
15,20,20,20,20,20,20,20,20,14,1,520,20,20,20,20,11,
11,15,20,20,20,20,20,20,24,22,22,25,20,20,20,14,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_6[] PROGMEM = {17,11,
8,8,
11,11,11,11,20,22,28,11,11,11,11,11,11,11,11,11,11,
11,11,10,11,20,22,28,12,11,11,11,11,11,11,11,11,11,
11,13,20,20,20,22,28,20,20,20,20,20,20,20,20,20,20,
11,20,20,20,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,19,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,19,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,20,20,20,20,22,28,20,20,20,19,20,20,20,20,20,20,
11,20,20,20,20,22,28,20,19,20,20,20,19,20,20,20,20,
11,15,20,20,20,22,28,20,20,20,20,20,20,20,20,20,20,
11,11,11,11,15,22,28,14,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,22,28,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_7[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,11,11,11,11,11,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,13,20,20,20,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,12,11,
20,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,12,
20,20,19,20,20,19,20,20,19,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,14,
20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,14,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};


const byte room_1_8[] PROGMEM = {17,11,
8,8,
11,11,11,11,11,11,11,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,11,10,13,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,11,13,20,20,20,20,11,11,11,11,11,11,11,
11,11,11,11,13,20,20,20,20,20,11,11,11,11,11,11,11,
11,11,11,13,20,20,20,20,20,20,11,11,11,11,11,11,11,
11,11,13,20,20,20,20,20,20,20,11,11,11,11,11,11,11,
11,13,20,20,20,20,20,20,20,20,12,11,11,11,11,11,11,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,};

const byte room_1_9[] PROGMEM = {17,11,
8,8,
11,11,2,20,2,20,2,20,20,20,2,20,2,20,2,20,2,
11,11,2,20,2,20,2,20,20,20,2,20,2,20,2,20,2,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,13,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
20,20,2,20,2,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
20,20,2,20,2,20,20,20,20,20,20,20,20,20,20,20,20,
11,15,20,20,20,20,2,20,20,20,2,20,2,20,2,20,20,
11,11,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
11,11,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
11,11,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,};

const byte bridge_h[] PROGMEM = {B01110111,B10001000,B10101010,B10001000,B10001000,B10101010,B10001000,B01110111,};
const byte bridge_v[] PROGMEM = {B01111110,B10000001,B10100101,B10000001,B01111110,B10000001,B10100101,B10000001,};
const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte dead_tree[] PROGMEM = {B10101001,B01010110,B01001001,B10101010,B01011010,B00111100,B00011000,B00011000,};
const byte dungeon_left_bottom[] = {B11111111,B10001111,B01001111,B11111111,B10001111,B01001111,B11111111,B10001111,};
const byte dungeon_left_top[] = {B00010001,B00101110,B00101010,B00101110,B01000000,B01000001,B10010010,B10001000,};
const byte dungeon_middle[] = {B10000001,B01000010,B00111100,B00000000,B00000000,B10011001,B00011000,B01000010,};
const byte dungeon_right_bottom[] = {B11111111,B11110001,B11110010,B11111111,B11110001,B11110010,B11111111,B11110001,};
const byte dungeon_right_top[] = {B10001000,B01110100,B01010100,B01110100,B00000010,B10000010,B01001001,B00010001,};
const byte grave_marker[] PROGMEM = {B00011000,B00111100,B01100110,B0100010,B01100110,B01100110,B00111100,B11111111,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B01001101,B10100100,B10010001,B01001010,B10010000,B01100101,B10001001,B01011010,};
const byte rock_valley_ne[] PROGMEM = {B10101010,B10010101,B01000100,B00101001,B00110010,B00001010,B00000100,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B01010101,B10101001,B00100010,B10010100,B01001100,B01010000,B00100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000100,B0011001,B00010010,B00101001,B01000110,B10110001,B10001010,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B00100000,B10011000,B01001000,B10010100,B01100010,B10001101,B01010001,};
const byte sand[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte statue[] PROGMEM = {B10111010,B11000110,B01101100,B11101110,B11111110,B11111110,B01101100,B01101100,};
const byte steps[] PROGMEM = {B01111110,B10000001,B00000000,B10000001,B01111110,B10000001,B00000000,B10000001,};
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 *spritesheet[] = {bridge_h, bridge_v, bush, dead_tree, dungeon_left_bottom, dungeon_left_top, dungeon_middle,
dungeon_right_bottom, dungeon_right_top, grave_marker, port_noir, rock_terrain_master, rock_valley_ne, rock_valley_nw,
rock_valley_se, rock_valley_sw, sand, statue, steps, turtle_rock, void_tile, water_left_bottom, water_left_middle, water_left_top,
water_middle_bottom, water_middle_middle, water_middle_top, water_right_bottom, water_right_middle, water_right_top};


int camerax = -20 ;
int cameray = -10 ;
int xmax = -68;


void drawTileMap(){
 if(gb.update()){
 gb.begin();

//////camera controls
if(player_x > 59 && camerax <  0 && camerax  > -52){player_x = 59;camerax--;}   
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camera boundary positions
else  if(player_x < 15 && camerax <  0 && camerax  > -52){player_x = 15;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
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--;}
//value 28 equals player position on right when camera will start to follow
//value 0 and -40 equals camera boundary positions
else  if(player_y < 15 && cameray < 0 && cameray >  -40){player_y = 15;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
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;
//value 0 and -52 equals camera boundary positions
      if(cameray > 0)cameray= 0;   
else  if(cameray < -40) cameray = -40;
//value 0 and -40 equals camera boundary positions
gb.display.drawTilemap(camerax,cameray,room_1_9,spritesheet);
}
}
  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))
    {
 if(gb.display.solid[i].spritecol == void_tile);
          if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == bridge_h );
         if(gb.display.solid[i].spritecol == sand);
         if(gb.display.solid[i].spritecol == steps );
else     if(gb.display.solid[i].spritecol == bush)return true;
else     if(gb.display.solid[i].spritecol == dead_tree)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_left_top)return true;
else     if(gb.display.solid[i].spritecol == dungeon_middle)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_bottom)return true;
else     if(gb.display.solid[i].spritecol == dungeon_right_top)return true;
else     if(gb.display.solid[i].spritecol == grave_marker)return true;
else      if(gb.display.solid[i].spritecol == port_noir)return true;
else      if(gb.display.solid[i].spritecol == rock_terrain_master)return true;//{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;

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



////////////player.ino
Code: Select all

const byte sever_front_black[] PROGMEM = {8,8,0x39,0x7d,0x01,0x01,0xfe,0x01,0x7c,0x46,};
const byte sever_front_grey[] PROGMEM = {8,8,0x82,0x82,0xd6,0x7c,0x01,0xa8,0x00,0x00,};
const byte sever_left_black[] PROGMEM = {8,8,0x9f,0xbe,0x80,0x82,0x7f,0x00,0x3e,0x62,};
const byte sever_left_grey[] PROGMEM = {8,8,0x00,0x00,0x17,0x3c,0x00,0x95,0x00,0x00,};
const byte sever_rear_black[] PROGMEM = {8,8,0x9c,0xbe,0xbe,0x80,0x7f,0x88,0x3e,0x62,};
const byte sever_rear_grey[] PROGMEM = {8,8,0x41,0x41,0x7f,0x3e,0x80,0x15,0x00,0x00,};
const byte sever_right_black[] PROGMEM = {8,8,0xf9,0x7d,0x01,0x41,0xfe,0x00,0x7c,0x46,};
const byte sever_right_grey[] PROGMEM = {8,8,0x00,0x00,0xe8,0x3c,0x00,0xa9,0x00,0x00,};





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

void move_player() {
  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(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_black);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
    }
      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,sever_front_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_grey);
    }
      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,sever_right_black);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_grey);
    }
      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,sever_left_black);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_grey);
    }
      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,sever_rear_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
        }
 }
     
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_grey);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_grey);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_black);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_grey);
        }
      }
}
 
}
   




User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: seperate sketches for seperate game aspects

Postby Sorunome » Sat Aug 20, 2016 5:43 am

since you also use spritesheet in map.ino i think you also have to make it extern const byte in there (well it's worth a shot ^.^ )
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: seperate sketches for seperate game aspects

Postby Duhjoker » Sat Aug 20, 2016 8:36 am

Ok I'm about to give up. I've added extern this and extern that, changed sprites to extern const byte. I must have tried 20 different compiled programs today. I don't understand what I'm doing wrong. Every thing worked together just fine.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Next

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 15 guests