Handling collisions
As collision detection is something we will need to implement for all the remaining projects in this book I thought a broader discussion beyond that which will be required for Pong might be useful. Furthermore, I am going to use some images from the 5th 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 and when they might...