Handling collisions
As collision detection is something that we will need to implement in all the remaining projects in this book, I thought a broader discussion beyond what is required for Pong might be useful. Furthermore, I am going to use some images from the fifth game project to visually demonstrate some topics around collision detection.
Collision detection is quite a broad subject, so here is a quick look at our options for collision detection and in which circumstances different methods might be appropriate.
Essentially, we just need to know when certain objects from our game touch other objects. We can then respond to that event by bouncing the ball, adding to the score, playing a sound, or whatever is appropriate. We need a broad understanding of our different options, so we can make the right decisions in any particular game.
Collision detection options
First, here are a few of the different ways we can use mathematics to detect collisions, how we can utilize...