We need to implement some solution not to have an endless game. To do this we will introduce maximum game time and we set it to 30 seconds.
Phase I
1) Add new field to the score object that will display the time remaining to the end of the game.
2) Save the game starting time to some global variable before the game starts
3) Introduce some flag variable reflecting of the game has ended or not
4) Before updating the game objects (background, monsters, hero, score), check the time till the end of the game. If there is not time left, set the game ended flag to true. If not, decrease the time till the end of the game.
5) Before updating the game objects check the game ended flag. If flag is set to true,
do not update the the game objects
show the new game object GameOverObject in the center of the screen (over other objects) saying "Game over! Your score is {{you score}}!"
Phase II
1) Add text "If you want to play again, press Space" to the GameOverObject
2) Monitor if Space is pressed, and if yes, start new game.
We need to implement some solution not to have an endless game. To do this we will introduce maximum game time and we set it to 30 seconds.
Phase I 1) Add new field to the score object that will display the time remaining to the end of the game. 2) Save the game starting time to some global variable before the game starts 3) Introduce some flag variable reflecting of the game has ended or not 4) Before updating the game objects (background, monsters, hero, score), check the time till the end of the game. If there is not time left, set the game ended flag to true. If not, decrease the time till the end of the game. 5) Before updating the game objects check the game ended flag. If flag is set to true,
GameOverObject
in the center of the screen (over other objects) saying "Game over! Your score is {{you score}}!"Phase II 1) Add text "If you want to play again, press Space" to the
GameOverObject
2) Monitor if Space is pressed, and if yes, start new game.