Understanding the language, error messages, etc.
Post a reply

[Solved]How to create splash-screens or deathscreens

Sat Oct 18, 2014 1:30 pm

I want to create a death-screen similar to that in crabator in which the whole screen is cleared and it shows your stats before death. How do you do that? Do I need to use separate .ino's?
Last edited by Sushi on Sun Oct 19, 2014 12:28 pm, edited 1 time in total.

Re: How to create splash-screens or deathscreens

Sun Oct 19, 2014 6:24 am

You can create a function called for example "showDeathScreen" which contains a loop that shows whatever you want, and breaks this loop whenever you press a button. It convenient to seperate the world/player updating function from the displaying function, so you can continue to draw the world without updating it. Something like this:

Code:
void showDeathScreen(){

  gb.sound.playPattern(deathSound,0); //start the death sound before entering the loop

  while(1){ //continuously loop to update the screen, sound an buttons
    if(gb.update()){
     
      drawWorld(); //continue to display the world using a function you created somewhere else
      gb.display.print(F("GAME OVER!")); //overlay a game over message
     
      //leave this function if button A or B is pressed
      if(gb.buttons.pressed(BTN_A) || gb.buttons.pressed(BTN_B)){
        gb.sound.playOK();
        return;
      }
     
    }
  }
}


So somewhere else in you code you can write something like
Code:
if(playerLife <= 0){
   showDeathScreen();
}
Post a reply