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:

  1. In 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 
  2. So far, Pierre has been flapping ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.