After learning how to create a level in the previous chapter, it is time to add a life line to our hero that slowly depletes overtime. In the game, our hero can die in a few ways. He can fall off the platform and hit the ground, go off the screen, collide with certain obstacles like TNT, or just run out of his life line. Because our hero is a pencil he will need to collect as many sharpeners as he can to increase his life line. The life line will be displayed on the top right hand corner of the screen. The goal is to reach the finish line before you run out of lead and not hit the ground. Let’s see how to achieve this.
We will discuss the following Swift concepts in this chapter: