First game and the tilemap

I started to code my first game yesterday on arduboy. I wan’t to make a simple jump&run first. So I read a bit about tiles etc. Then i created a simple tile and player bitmap. Now i want to store the map in an tile map. Isn’t it possible to store the map in just a simple char array? Because when i draw the tiles from such an array nothing happens. In the following code it should at least draw the tiles in the first row…

const unsigned char tile1[] PROGMEM  = {
    0xff, 0xff, 0x33, 0x33, 0x3, 0x3, 0xf, 0xf, 0xc3, 0xc3, 0x3, 0x3, 0xcf, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xf3, 0xf3, 0xc0, 0xc0, 0xcc, 0xcc, 0xc0, 0xc0, 0xcc, 0xcc, 0xff, 0xff,  
};    
const unsigned char maparray[] PROGMEM = {
      0,1,0,0,0,0,0,0,
      0,1,0,0,1,1,1,0,
      1,1,1,1,1,1,1,1
    };

int bgcounterX = 1;
int bgcounterY = 1;

void setup() {
  arduboy.begin();
  arduboy.clear();
  arduboy.setFrameRate(60);
  
  for(char x = 0; x<=24; x++)
  {
    if(maparray[x] == 1)
    {
      arduboy.drawBitmap(bgcounterX,bgcounterY,tile1,16,16,WHITE);
    }
    
    bgcounterX = bgcounterX +16;
  } 
  arduboy.display();
}

After that i would increase the bgcounterY to draw the next line. Where is my problem?

You’ve put maparray[] in PROGMEM, so you can’t just directly reference it. You need to use something like:

if (pgm_read_byte(maparray + x) == 1)
1 Like

Wow i never thought about the storage. Thanks for the help and the link! I see that there is much more to keep in mind when programming for such a board :blush: Can anyone maybe recommend a book for the basics of game programming in such a ‘low level’ way and without an engine?

2 Likes