Detecting collisions
We just need to know when certain objects from our game touch certain other objects. We can then respond to that event in an appropriate manner. In our classes, we have already added functions to call when our objects collide. They are the following:
- The
Player
class has ahit
function. We will call it when a zombie collides with the player. - The
Zombie
class has ahit
function. We will call it when a bullet collides with a zombie. - The
Pickup
class has agotIt
function. We will call it when the player collides with a pickup.
If necessary, look back to refresh your memory on how each of those functions works. All we need to do now is detect the collisions and call the appropriate functions. We will use rectangle intersection to ...
Get Beginning C++ Game Programming 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.