The next important step is that
user-input should do different things
depending on the game_mode.
- In pre-start mode, it changes to running mode.
- In running mode, it makes the bird jump.
- In game-over mode, it resets the game and puts it back in running mode. (Why not back to pre-start mode? Well, we're saying "click to play again", so if they click, we need to start playing straight away without going through the initial welcome-screen again)
function Got_Player_Input(MyEvent) {
switch (game_mode) {
case 'prestart': {
game_mode = 'running';
break;
}
case 'running': {
bird.velocity_y = jump_amount;
break;
}
case 'over': {
reset_game();
game_mode = 'running';
break;
}
} // switch
MyEvent.preventDefault();
}
Hopefully you can see that the
English description pretty much matches the code one-for-one.
The reset_game function doesn't exist yet. That's next.