The code above also mentions another state: ‘stateMenu’:
if(StateActive.time()>3 || Kb.bp(KB_ESC)) {
StateMenu.set(1.0);
}
In other words: we will wait 3 seconds in this state, or until the user presses escape. At that time, another application state will become active, with a crossfade of 1 second between them. The menu state could be something like this:
Deze nieuwe state zou er zo kunnen uitzien:
bool InitMenu() {return true;}
void ShutMenu() {}
bool UpdateMenu()
5{
if(Kb.bp(KB_ESC))return false;
if(Kb.bp(KB_ENTER))StateGame.set(0.5);
return true;
}
10
void DrawMenu()
{
D.clear(GREY);
D.text (0, 0 , ”Menu”);
15 D.text (0, -0.3, ”Press Enter to start the game”);
D.text (0, -0.5, ”Press Escape to exit”);
}
State StateMenu(UpdateMenu, DrawMenu, InitMenu, ShutMenu);
20
This state is very similar to the previous one. But this time we can use the Enter key to enter the actual game.