September 2018
Intermediate to advanced
434 pages
8h 47m
English
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:
Player.swift, add some new properties directly to the Player 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 Read now
Unlock full access