Making the bullets fly
In the following sections, we will make the bullets usable with these six steps:
- Add the necessary include directive for the
Bullet
class. - Add some control variables and an array to hold some
Bullet
instances. - Handle the player pressing R to reload.
- Handle the player pressing the left mouse button to fire a bullet.
- Update all bullets that are in flight in each frame.
- Draw the bullets that are in flight in each frame.
Including the Bullet class
Add the include directive to make the Bullet
class available:
#include <SFML/Graphics.hpp>
#include "ZombieArena.h"
#include "Player.h"
#include "TextureHolder.h"
#include "Bullet.h"
using namespace sf;
Let’s move on to the next step.
Control variables and the bullet array
Here are some variables to keep track of clip sizes, spare bullets, the remaining bullets in the clip, the current rate of fire...