Collideables
There are many times that we may want to check and see whether objects in the game have collided with each other. We may want to see whether the player has struck an obstacle or an enemy. We may have objects that the player can pick up, often called pickups or powerups.
Collectively, objects in the game that can collide with other objects are known as collideables. When we created our Sprite
class, we actually it designed for this. Looking at the class constructor, you will notice that member variable m_isCollideable
is set to false
. When we write our collision detection code, we will ignore objects that have m_isCollideable
set to false
. If we want to allow an object to collide with other objects, we have to make sure to set m_collideable
to true
.
Ready to score
To keep our design simple, we are going to create one enemy and one pickup. Running into an enemy will subtract points from the player's score, while running into the pickup will increase the player's score...