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...

Starting the Zombie Arena game engine


In this game, we will need a slightly upgraded game engine in main. In particular, we will have an enumeration called state which will track what the current state of the game is. Then, throughout main, we can wrap parts of our code so that different things happen in different states.

Right-click on the HelloSFML file in the Solution Explorer and select Rename. Change the name to ZombieArena.cpp. This will be the file that contains our main function and the code that instantiates and controls all our classes.

We begin with the now familiar main function and some include directives. Note the addition of an include directive for the Player class.

Add the code following to the ZombieArena.cpp file:

#include "stdafx.h" 
#include <SFML/Graphics.hpp> 
#include "Player.h" 
 
using namespace sf; 
 
int main() 
{ 
 
   return 0; 
} 

The previous code has nothing new in it except that the #include "Player.h" line means we can now use the Player class within...