Need some help

Hi everybody,

I’m back making my game, and I have a problem. When the game is over I want to just display the score(I tried the gb.display.print code). So I have no idea why this won’t work, maybe it can’t display variables(int)? What should I do?
Thanks for the answer!

Beni0121

Please share your code to let me have Ă  look on it

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

//Változó deklaráció

int playerPos = 0;
int birdPosX = 98;
int birdPosY = 10;
int birddead = 0;
int bulletX = 0;
int bulletY = 30;
bool canShoot = false;
bool canShoot1 = false;
bool canShootminus1 = false;
int birdspeed = 1;
int score = 0;
int lives = 3;
bool gameIsRunning = true;

void setup() {
gb.begin();
gb.display.setFont(font5x7);
gb.titleScreen(logo);

const byte Huntersprite[][32] PROGMEM =
{
15,15,
B00000000,B00000100,
B00000000,B00001000,
B00111010,B00010000,
B01000100,B01100000,
B00110101,B10000000,
B01100110,B00000000,
B00100100,B01000000,
B00011000,B11000000,
B00101101,B10000000,
B00111111,B00000000,
B01000010,B00000000,
B01000010,B00000000,
B01000010,B00000000,
B10000001,B00000000,
B10000001,B00000000,

};

const byte Huntersprite2[][20] PROGMEM =
{
8,18,
B00010000,
B00010000,
B00010000,
B00010000,
B00011000,
B00100100,
B01011010,
B01100110,
B01011110,
B00100100,
B00111100,
B01000010,
B01000010,
B10000001,
B10000001,
B10000001,

};

const byte Huntersprite3[][32] PROGMEM =
{
15,15,
B00100000,B00000000,
B00010000,B00000000,
B00001000,B01011100,
B00000110,B00110010,
B00000001,B10101100,
B00000000,B01100110,
B00000000,B00100100,
B00000010,B00011000,
B00000011,B00110100,
B00000001,B11111100,
B00000000,B01000010,
B00000000,B01000010,
B00000000,B01000010,
B00000000,B10000001,
B00000000,B10000001,

};

const byte bullet[][4] PROGMEM =
{
8,2,
B10000000,
B10000000,
};

const byte Pigeonsprite1[][12] PROGMEM =
{
14,5,
B11111000,B00000000,
B00000100,B00000000,
B00000101,B11111000,
B00000010,B00000100,
B00000100,B00000100,
};

const byte Pigeonsprite2[][12] PROGMEM =
{
14,5,
B00000000,B00000000,
B01111100,B01111000,
B10000010,B10000100,
B10000001,B00000100,
B00000000,B00000100,
};

const byte Pigeonsprite3[][12] PROGMEM =
{
14,5,
B00000000,B01111100,
B00000000,B10000000,
B01111110,B10000000,
B10000001,B00000000,
B10000000,B10000000,
};

const byte Background[][464] PROGMEM =
{
88,42,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00001000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00011000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00100100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B01000010,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B01100110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000001,B10000000,B00000000,B00000000,B00000000,
B00100100,B00000000,B00000001,B11111100,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,
B01000010,B00000000,B00000010,B00000010,B00000000,B00000000,B11100010,B00000000,B00000000,B00000000,B00000000,
B10000001,B00000000,B00000100,B00000001,B00000000,B00000000,B00010010,B01110000,B00000000,B00000000,B00000000,
B11100111,B00000000,B00000100,B00000001,B00000000,B00000001,B10001010,B10001000,B00000000,B00000000,B00000000,
B00100100,B00000000,B00000100,B00000001,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000000,
B01000010,B00000000,B00000010,B00000010,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,
B10000001,B00000000,B00000000,B10000100,B00000000,B00000001,B11100100,B10000000,B00000000,B00000000,B00000000,
B00000000,B10000000,B00000000,B01111000,B00000000,B00000010,B00010100,B10000000,B00000000,B00000000,B00000000,
B11100111,B10000000,B00000011,B01001100,B00000000,B00000100,B00001100,B10000000,B00000000,B00000000,B00000000,
B01000010,B00000000,B00000000,B11001011,B10000000,B00000100,B00001100,B10000000,B00000000,B00000000,B00000000,
B10000001,B00000000,B00000000,B01001000,B00000000,B00000100,B00001100,B10000000,B00000000,B00000000,B00000000,
B00000000,B10000000,B00000000,B01001000,B00000000,B00000010,B00010100,B10000000,B00000000,B00000000,B00000000,
B00000000,B01000000,B00000000,B01001000,B00000000,B00000001,B11100100,B10000000,B00000000,B00000000,B00000000,
B11111111,B11000000,B00000000,B01001000,B00000000,B00000000,B10100100,B10000000,B00000000,B00000000,B00000000,
B00100100,B00000000,B00000000,B01001000,B00000000,B00000000,B10100100,B10000000,B00000000,B00000000,B00000000,
B00100100,B00000000,B00000000,B01001000,B00000000,B00000000,B10100100,B10000000,B00000000,B00000000,B00011000,
B00100100,B00000000,B00000000,B01001000,B00000000,B00000000,B10100100,B11110000,B00000000,B00000000,B00010100,
B11100100,B00000000,B00000000,B01111000,B00000000,B00000000,B10100101,B00001000,B00000000,B00000000,B01100010,
B01100100,B00000000,B00000000,B10001000,B00000000,B00000000,B10100110,B00000100,B00000000,B00000001,B11000001,
B00010100,B00000000,B00000001,B00001000,B00000000,B00000000,B10100100,B00000010,B00000000,B00000001,B00000000,
B00010100,B00000000,B00000001,B00000100,B00000000,B00000000,B10101000,B00000001,B00000000,B00000110,B00000000,
B00001100,B00000000,B00000010,B00000100,B00000000,B00000000,B10110000,B00000001,B00000000,B00011000,B00000000,
B00001100,B00000000,B00001100,B00000100,B00000000,B00010000,B11100000,B00000000,B00000000,B00100000,B00000000,
B00000100,B00000000,B00010000,B00000010,B00000000,B00101111,B10000000,B00000000,B00000000,B00100000,B00000000,
B00000010,B00000000,B00010000,B00000010,B00000000,B00100110,B00000000,B00000000,B00000000,B11000000,B00000000,
B00000010,B00000000,B00100000,B00000001,B10000000,B00100000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000001,B00000000,B00000000,B00000000,B10000000,B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,

};
// the setup routine runs once when Gamebuino starts up
void setup(){
// initialize the Gamebuino object
gb.begin();
//display the main menu:
gb.titleScreen(F(“Pigeon Season”));

};

// the main loop
void loop(){

//a háttér megrajzolása
gb.display.drawBitmap(0, 0, Background[0]);

if(gb.update()){
//gb.display.drawBitmap(10,10,sprite[0]);

if (gb.buttons.pressed(BTN_LEFT)) {
  if (playerPos > -2) {
    playerPos--;
    canShoot == true;
   // if (gb.buttons.pressed(BTN_A)) {
     // bulletX++;
     // bulletY--;
    //}
  }
}

if (gb.buttons.pressed(BTN_RIGHT)) {
  if (playerPos < 2) {
    playerPos++;
    canShoot == true;
      /*if (gb.buttons.pressed(BTN_A)) {
      bulletX--;
      bulletY--;
    }*/
  }
}

if (gb.buttons.pressed(BTN_A)) {
 if (playerPos == 0) {
   canShoot = true;
   }
  if (playerPos == -1) {
    canShootminus1 = true;
   }
  if (playerPos == 1) {
    canShoot1 = true;
   }
  }
     
 
if (playerPos == -2) {
  playerPos = -1;   
}

if (playerPos == 2) {
  playerPos = 1;
}

if (bulletY <= 1) {
  canShoot = false;
  bulletY = 30;  
}

if (playerPos == 0) {
  gb.display.drawBitmap(34,30,Huntersprite2[0]);
  bulletX = 42;
}
if (playerPos == -1) {
  gb.display.drawBitmap(10,30,Huntersprite2[0]);
  bulletX   = 18;
}
if (playerPos == 1) {
  gb.display.drawBitmap(64,30,Huntersprite2[0]);
  bulletX = 68;
}

if (canShoot == true) {
  bulletY--;
  gb.display.drawBitmap(bulletX,bulletY,bullet[0]);
  playerPos = 0;
 if (bulletY <= 1) {
  canShoot = false;
  bulletY = 30;  
 }
}
if (canShoot1 == true) {
  bulletX--;
  bulletY--;
  gb.display.drawBitmap(bulletX, bulletY,bullet[0]);
  playerPos = 1;
 if (bulletY <= 1) {
  canShoot1 = false;
  bulletY = 30;  
 }  
}
if (canShootminus1 == true) {
  bulletX++;
  bulletY--;
  gb.display.drawBitmap(bulletX, bulletY,bullet[0]);
  playerPos = -1;  
 if (bulletY <= 1) {
  canShootminus1 = false;
  bulletY = 30;  
 }
}


if (birddead == 0) {
  gb.display.drawBitmap(birdPosX,birdPosY,Pigeonsprite1[0]);
  birdPosX = birdPosX - birdspeed;
}

//a madár és a töltény ütközése

if (birdPosX <= bulletX && (birdPosX + 14) >= bulletX && bulletY == 10 ) {      
  birdPosX = 98;
  score++;
  if (score % 5 == 0) {
    birdspeed++;
    }
}

//a madár elérte a képernyő bal szélét ezért újraindítjuk
if (birdPosX == -14) {
lives–;
birdPosX = 98;
}

gb.display.cursorY=0;
gb.display.cursorX=0;
gb.display.print(score);

gb.display.cursorY=0;
gb.display.cursorX=75;
gb.display.print(lives);

//a játék vége
if (lives => 0) {
gb.display.cursorY=10;
gb.display.cursorX=42;
gb.display.print(score);

if (lives == -1) {
  gb.display.cursorY=10;
  gb.display.cursorX=42;
  gb.display.print("Press A to restart");
  };

/if (birdPosX <= 14) {ss
gb.display.drawBitmap(birdPosX++,birdPosY,Pigeonsprite1[0]);
}
if (birdPosX >= 70) {
gb.display.drawBitmap(birdPosX–,birdPosY,Pigeonsprite1[0]);
};
/

};

};
};

Here you are

OK, you can use: gb.display.printf("%d",score);

1 Like

this looks wrong, I think it should look like this:
if (lives >= 0)

2 Likes

You found it makerSquirrel, i think :wink:

1 Like