Game Development Reference
In-Depth Information
Chapter 10
Limited Lives
In this chapter, you make the Painter game more interesting by giving the player a limited number of
lives. If players miss too many paint cans, they die. The chapter discusses how to deal with that and
how to display the current number of lives to the player. In order to do the latter, you learn about a
few programming constructs for repeating a group of instructions several times.
Maintaining the Number of Lives
To introduce some danger and incentive to work hard in the game, you would like to limit the number
of paint cans of the wrong color that the player can allow to fall through the bottom of the screen.
The Painter8 example adds this kind of behavior to the game and uses a limit of five.
The choice of a limit of five paint cans is one of many examples of the decisions you have to make
as a game designer and developer. If you give the player only a single life, then the game will be too
hard to play. Giving the player hundreds of lives removes the incentive for the player to play well.
Determining such parameters often happens by play-testing the game and determining reasonable
parameter values. In addition to testing the game yourself, you can also ask your friends or family to
play your game to get some idea of what values to choose for these parameters.
In order to store the life limit, you add an extra member variable to the PainterGameWorld class:
this.lives = 5;
You initially set this value to 5 in the constructor of the PainterGameWorld class. Now you can update
the value whenever a paint can falls outside the screen. You perform this check in the update method
of the PaintCan class. Therefore, you have to add a few instructions in that method to deal with this.
The only thing you need to do is check whether the color of the paint can is the same as its target
color when it falls through the bottom of the screen. If that is the case, you have to decrement the
lives counter in the PainterGameWorld class.
131
 
Search WWH ::




Custom Search