Book Image

Beginning C++ Game Programming

Book Image

Beginning C++ Game Programming

Overview of this book

This book is all about offering you a fun introduction to the world of game programming, C++, and the OpenGL-powered SFML using three fun, fully-playable games. These games are an addictive frantic two-button tapper, a multi-level zombie survival shooter, and a split-screen multiplayer puzzle-platformer. We will start with the very basics of programming, such as variables, loops, and conditions and you will become more skillful with each game as you move through the key C++ topics, such as OOP (Object-Orientated Programming), C++ pointers, and an introduction to the Standard Template Library. While building these games, you will also learn exciting game programming concepts like particle effects, directional sound (spatialization), OpenGL programmable Shaders, spawning thousands of objects, and more.
Table of Contents (24 chapters)
Beginning C++ Game Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Dedication
Preface
17
Before you go...

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 to keep track of bullets, clip sizes, bullets spare/remaining, bullets in the clip, the current rate of fire (starting at one per second), and the time when the last bullet was fired.

Add the highlighted...