Play and play again callbacks

After our changes to the game loop, we need to add some callback functions for our buttons. The first of these functions is the play_click function. This is the callback that runs when the player clicks the play button on the start screen. This function will set the current screen to the play transition and set the transition time to 1,020 milliseconds:

void play_click() {
current_screen = PLAY_TRANSITION;
transition_time = 1020;
}

After that, we will define the play_again_click callback. This function runs when the player clicks the play again button on the game over screen. Because this is a web game, we will use a little trick to simplify this logic. In a game written for almost any other platform, you would need to create some reinitialization logic that would have to go back through your game and reset the state of everything. We are going to cheat by simply reloading the web page using JavaScript:

void play_again_click() {
EM_ASM(
location.reload();
);
}

This cheat won't work for all games. Reloading some games would cause unacceptable delays. For some games, there may be too much state information that we need to keep. However, for this game, reloading the page is a quick and easy way to get the job done.