We have done a lot of things in this chapter, and I have explained many things. I am afraid this chapter is a bit hard to understand. Don't give up, and don't stop because we are nearing the end of the chapter. Now that we have added our state-change feature, it is time to apply a losing condition to the game. There are two losing conditions in this game: when the player loses all lives and when the time runs out. To do this, we'll give default values to the global variables related to the losing conditions. We'll give three lives and start the time countdown at 60 at the start of the level, like this:
Then, we'll represent these values on screen like we did in our first game. So, we'll create two new Text
objects to be put on the HUD layer, name them txtTime
and txtLife
, and make their values show gameTime
and life instance variables as follows:
To show that the player has lost, we will display GAME OVER text in large when one of the losing conditions is met. So, create another...