Chapter    20

Interaction Between Game Objects

In this chapter, you are going to program the main gameplay for the Penguin Pairs game. You will learn how to move penguins around on the board and what to do when a penguin collides with another game object, such as a shark or another penguin.

Defining Operators

Since you will be dealing with moving and colliding penguins, you will be doing quite a lot of calculations with two-dimensional points and vectors (represented by CGPoint instances). At the moment, computing things with these points is a bit of a hassle. For example, in the LevelState class, this is how you have to position the Quit button:

quitButton.position = GameScreen.instance.topRightquitButton.position.x -= + 10 ...

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.