Chapter    9

Limited Lives

In this chapter, you will make the Painter game more interesting by giving the player a limited number of lives. If players miss too many paint cans, the game is over. 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 will learn 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 Painter7 example adds this kind of behavior to the game and uses a limit of five.

The choice ...

Get Swift Game Programming for Absolute Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.