Adding projectiles
Finally, time to add what makes a game fun. Shooting down stuff is essential for our game. The code to interact with the W
orld class is already defined, thanks to the actions in Player and to the existing Entity base class. All that's left is to define the projectiles themselves.
We start with the Projectile class. We have normal machine gun bullets and homing missiles represented by the same class. This class inherits from the Entity class and is quite small, since it doesn't have anything special that differentiates it from other entities apart from collision tests, which we will talk about later.
class Projectile : public Entity
{
public:
enum Type
{
AlliedBullet,
EnemyBullet,
Missile,
TypeCount
};
public:
Projectile(Type type, const TextureHolder& textures);
void guideTowards(sf::Vector2f position);
bool isGuided...