Gamebuino Coding Problem

Hi Folks,
I'm trying to program a video game on a "Gamebuino"-style device that I built using an Arduino Uno and a Nokia 5110.
The problem is, I can't seem to get the tilemap to work. It only reads the first character of the map and won't go to the next line. It also displays the character more times than it needs to. I've included the code below, as well as an image of what the code is displaying.
Just let me know if you have questions, and thanks for the help!

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

Gamebuino gb;

int TileCursorX = 0;
int TileCursorY = 0;
int DrawPosX = 0;
int DrawPosY = 0;
const byte Logo[] PROGMEM = {64, 35, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B01100111, B01110111, B01000111, B00011000, B10011101, B00000000, B00000000, B00000011, B01010010, B00100010, B01000100, B00010101, B01001001, B00000000, B00000000, B00000011, B01100010, B00100010, B01000110, B00011001, B11001001, B00000000, B00000000, B00000011, B01010010, B00100010, B01000100, B00010101, B01001000, B00000000, B00000000, B00000011, B01100111, B00100010, B01110111, B00011001, B01001001, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B11110011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B10000001, B11110011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000101, B01000000, B11100011, B00000000, B00000000, B00000000, B00000000, B00000000, B01111111, B11111111, B11111111, B11000000, B00000000, B00000000, B00000000, B00000000, B01111111, B11111111, B11111111, B11000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11000010, B00000000, B00000000, B00000000, B10000000, B00000000, B00000000, B00000000, B11000010, B00000000, B00000000, B00000011, B11100000, B00000000, B00000000, B00000000, B11111111, B11110000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B11111111, B11110000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B11100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B01000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B01000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,};
const byte Player[] PROGMEM = {8, 8, B00011000, B11111111, B11111111, B11000011, B11000011, B11000011, B11111111, B11111111};
const byte Wall1[] PROGMEM = {8, 8, B11111111, B11000011, B10100101, B10011001, B10011001, B10100101, B11000011, B11111111};
const byte Wall2[] PROGMEM = {8, 8, B11111111, B11111111, B11111111, B11100111, B11100111, B11111111, B11111111, B11111111};
const byte Wall3[] PROGMEM = {8, 8, B11011111, B11011111, B00000000, B11111110, B11111110, B00000000, B11011111, B11011111};

const unsigned char Map1[] PROGMEM {
  3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0,
  2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3, 3, 2, 2, 2, 2, 2, 3, 0, 2, 0,
  3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
  2, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0,
  2, 2, 2, 2, 2, 2, 0, 3, 0, 2, 2
};

void setup() {
  gb.begin();
  gb.titleScreen(Logo);
}

void loop() {
  gb.update();
  if (pgm_read_byte(Map1) == 0) {
    TileCursorX ++;
    DrawPosX = DrawPosX + 8;
  }
  if (pgm_read_byte(Map1) == 2) {
    TileCursorX ++;
    DrawPosX = DrawPosX + 8;
    gb.display.drawBitmap(DrawPosX, 0, Wall1);
  }
  if (pgm_read_byte(Map1) == 3) {
    TileCursorX ++;
    DrawPosX = DrawPosX + 8;
    gb.display.drawBitmap(DrawPosX, 0, Wall2);
  }
  if (pgm_read_byte(Map1) == 4) {
    TileCursorX ++;
    DrawPosX = DrawPosX + 8;
    gb.display.drawBitmap(DrawPosX, 0, Wall3);
  }
  if (TileCursorX == 11) {
    TileCursorY ++;
    TileCursorX = 0;
    DrawPosY ++;
  }
}

  if (pgm_read_byte(Map1) == 0)

Map1 is an array

Shouldn't you be reading one of its elements, possibly calculated from the values of TileCursorX and TileCursorY ?

You still have this in the code

    if (pgm_read_byte(Map1) == 0)

Which byte in the Map1 array is this statement testing and how will it ever test a different byte ?

Suppose that you want to read the byte at x = 2, y = 3 then given the values of x and y, which you have, can you calculate whereabouts in the array the value is held ?

Thanks! How do I insert those values into the pgm_read_byte?

Also, I thought I put a "for" loop into the code.

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

Gamebuino gb;

int DrawPosX = 0;
int DrawPosY = 0;

const byte Logo[] PROGMEM = {64, 35, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B01100111, B01110111, B01000111, B00011000, B10011101, B00000000, B00000000, B00000011, B01010010, B00100010, B01000100, B00010101, B01001001, B00000000, B00000000, B00000011, B01100010, B00100010, B01000110, B00011001, B11001001, B00000000, B00000000, B00000011, B01010010, B00100010, B01000100, B00010101, B01001000, B00000000, B00000000, B00000011, B01100111, B00100010, B01110111, B00011001, B01001001, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B11110011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B00000000, B10100011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B10000001, B11110011, B00000000, B00000000, B00000000, B00000000, B00000000, B00000101, B01000000, B11100011, B00000000, B00000000, B00000000, B00000000, B00000000, B01111111, B11111111, B11111111, B11000000, B00000000, B00000000, B00000000, B00000000, B01111111, B11111111, B11111111, B11000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11000010, B00000000, B00000000, B00000000, B10000000, B00000000, B00000000, B00000000, B11000010, B00000000, B00000000, B00000011, B11100000, B00000000, B00000000, B00000000, B11111111, B11110000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B11111111, B11110000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000010, B00100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000011, B11100000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B01000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B01000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000001, B11111111, B11111111, B11111111, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000};
const byte Player[] PROGMEM = {8, 8, B00011000, B11111111, B11111111, B11000011, B11000011, B11111111, B11111111, B01000010};
const byte Wall1[] PROGMEM = {8, 8, B11111111, B11000011, B10100101, B10011001, B10011001, B10100101, B11000011, B11111111};
const byte Wall2[] PROGMEM = {8, 8, B11111111, B11111111, B11111111, B11100111, B11100111, B11111111, B11111111, B11111111};
const byte Wall3[] PROGMEM = {8, 8, B11011111, B11011111, B00000000, B11111110, B11111110, B00000000, B11011111, B11011111};

const unsigned char Map1[] PROGMEM {
  4, 0, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 1, 0, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 4,
  4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
};

void setup() {
  gb.begin();
  gb.titleScreen(Logo);
}

void loop() {
  gb.update();
  for (char x = 0; x <= 11; x++)
  {
    if (pgm_read_byte(Map1) == 0) {
      DrawPosX = DrawPosX + 8;
    }
  }
  for (char x = 0; x <= 11; x++)
  {
    if (pgm_read_byte(Map1 + x) == 1) {
      gb.display.drawBitmap(DrawPosX, DrawPosY, Player);
      DrawPosX = DrawPosX + 8;
      gb.update();
    }
  }
  for (char x = 0; x <= 11; x++)
  {
    if (pgm_read_byte(Map1 + x) == 2) {
      gb.display.drawBitmap(DrawPosX, DrawPosY, Wall1);
      DrawPosX = DrawPosX + 8;
      gb.update();
    }
  }
  for (char x = 0; x <= 11; x++)
  {
    if (pgm_read_byte(Map1 + x) == 3) {
      gb.display.drawBitmap(DrawPosX, DrawPosY, Wall3);
      DrawPosX = DrawPosX + 8;
      gb.update();
    }
  }
  for (char x = 0; x <= 11; x++)
  {
    if (pgm_read_byte(Map1 + x) == 4) {
      gb.display.drawBitmap(DrawPosX, DrawPosY, Wall3);
      DrawPosX = DrawPosX + 8;
      gb.update();
    }
  }
  if (DrawPosX == 81) {
    DrawPosX = 0;
    DrawPosY == DrawPosY + 8;
  }
}

After all this time I am lost as to where you are stuck

Well, why don't you re-read the forum?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.