Teaching our penguin to fly
Let's implement the control scheme for our penguin. The player can tap anywhere on the screen to make Pierre fly higher and release to let him fall. We are going to make quite a few changes-if you need help, refer to the checkpoint at the end of this chapter. Start by modifying the Player
class; follow these steps to prepare our Player
for flight:
In
Player.swift
, add some new properties directly to thePlayer
class:       // Store whether we are flapping our wings or in free-fall:       var flapping = false       // Set a maximum upward force.       // 57,000 feels good to me, adjust to taste:       let maxFlappingForce:CGFloat = 57000       // Pierre should slow down when he flies too high:       let maxHeight:CGFloat = 1000
So far, Pierre has been flapping his wings by default. Instead, we want to display the soaring animation by default and only run the flap animation when the user presses the screen. In the
init
function, remove the line...