insert a menu in a game

General

Mrrrtijn

4 years ago

Hi Guys!  I'm working on my first game. On request of my daughter I wrote a game where a character from her favorite cartoon ' The Amazing world of Gumball' is avoiding arrows coming from the sky. Coding was not really hard, the game works fine. But I want now to insert a menu at the beginning of the game where you can choose a character to play with. coding this menu is no problem. The problem is that, because this menu is part of the loop function the menu is coming back to the game once the game() function has run once. And of course this is not what I want. The only time the menu must come back is when the game is over and you want to start over again.  Who can help me out?

#include <Gamebuino-Meta.h>
// some variables for the game and images

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

void loop() {

while(!gb.update());
gb.display.clear();
menu (); // this is the function in orde to select the Gumball character for your game
game();  // this is the actual game where you play the game with 1 of the characters

}

chris-scientist

NEW 4 years ago

Hello,

You can to use state of your game, by example :

#include <Gamebuino-Meta.h>
// some variables for the game and images

uint8_t stateOfGame;

void setup() {
  gb.begin();
  stateOfGame = 0;
}
void loop() {
  while(!gb.update());
  gb.display.clear();

  switch(stateOfGame) {
    case 0:
      menu (); // this is the function in orde to select the Gumball character for your game
      stateOfGame = 1;
      break;
    case 1:
      game();  // this is the actual game where you play the game with 1 of the characters
      break;
  }
}

Mrrrtijn

4 years ago

Hi Chris, I will look into that, thx!

Mrrrtijn

NEW 4 years ago

chris-scientist chris-scientist

Hi Chris, I will look into that, thx!

Mrrrtijn

NEW 4 years ago

Chris, it is working. thank you for your help!