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 -= quitButton.center.x + 10 ...

Get Swift Game Programming for Absolute Beginners 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.