O'Reilly logo

Beginning C++ Game Programming by John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making the bullets fly

We will make the bullets usable with the following six steps:

  1. Add the necessary include directive for the Bullet class.
  2. Add some control variables and an array to hold some Bullet instances.
  3. Handle the player pressing R to reload.
  4. Handle the player pressing the left mouse button to fire a bullet.
  5. Update all bullets that are in flight, in each frame.
  6. 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 "stdafx.h" 
#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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required