For the final section of this chapter, let's add some collision detection so that the rocket actually kills an enemy when they both come into contact with each other:
- Create a new function called checkCollision, and then create a prototype for it at the top of the main function:
void spawnEnemy(); void shoot(); bool checkCollision(sf::Sprite sprite1, sf::Sprite sprite2);
- This function takes two sprites so that we can check the intersection of one with the other. Add the following code for the function in the same place that we added the shoot function:
void shoot() { Rocket* rocket = new Rocket(); rocket->init("Assets/graphics/rocket.png",
hero.getSprite().getPosition(), 400.0f); rockets.push_back(rocket); } bool checkCollision(sf::Sprite sprite1, sf::Sprite sprite2) { sf::FloatRect shape1 = sprite1...