This is the longest chapter of the book. There is a fair amount of theory, but the theory will give us the knowledge to start using Object-Oriented Programming (OOP) to powerful effect. Furthermore, we will not waste any time in putting that theory to good use. Before we explore C++ OOP, we will find out about and plan our next game project.
This is what we will do in the following chapter:
Player
classView
classPlayer
class to workAt this point, if you haven't already, I suggest you go and watch a video of Over 9,000 Zombies (http://store.steampowered.com/app/273500/) and Crimson Land (http://store.steampowered.com/app/262830/).
Our game will obviously not be as in-depth or advanced as either of the examples but we will have the same basic set of features and game mechanics:
There will be three types of zombie to splatter. They will have different attributes such as appearance, health, and speed. We will call them chasers, bloaters, and crawlers. Take a look at this annotated screenshot of the game to see some of the features in action and the components and assets that make up the game:
Here is a little bit more information about each of the numbered points:
We have a lot to do and new C++ skills to learn. Let's start by creating a new project.
Creating a new project is now extremely easy. Just follow these straightforward steps in Visual Studio:
ZombieArena
and also make sure that the Create directory for solution option is checked. Now click OK..dll
files into the main project directory. My main project directory is D:Visual Studio StuffProjects ZombieArenaombieArena
. This folder was created by Visual Studio in the previous step. If you put your Projects
folder somewhere else then perform this step there instead. The files we need to copy in to the Projects
folder are located in your SFMLin
folder. Open a window for each of the two locations and highlight the required .dll
files.Now copy and paste the highlighted files into the project. The project is now set up and ready to go.
The assets in this project are more numerous and diverse than the previous game. The assets include:
All the graphics for the character, zombies, background, and sound required for the game are included in the download bundle. They can be found in the Chapter 6/graphics
, and Chapter 6/sound
folders, respectively.
The font that is required has not been supplied. This is because I wanted to avoid any possible ambiguity regarding the license. This will not cause a problem though, as I will show you exactly where and how to choose and download fonts for yourself.
Although I will provide either the assets themselves or information on where to get them, you might like to create and acquire them for yourself.
The graphical assets make up the parts of the scene that is our Zombie Arena game. Take a look at the graphical assets and it should be clear where in our game they will be used:
What might be less obvious, however, is the background_sheet.png
which contains four different images. This is the sprite-sheet I mentioned previously, and we will see how we can use one to save memory and increase the speed of our game in Chapter 7, C++ References, Sprite Sheets, and Vertex Arrays.
The sound files are all .wav
format. These are files which contain the sound effects that we will play at certain events throughout the game. They are:
hit.wav
: A sound that plays when a zombie comes into contact with the playerpickup.wav
: A sound that plays when the player touches (collects) a health boost (pick-up)powerup.wav
: A sound that plays when the player chooses an attribute to increase (power-up) in between each wave of zombiesreload.wav
: A satisfying click to let the player know they have loaded a fresh clip of ammunitionreload_failed.wav
: A less satisfying sound that indicates failure to load new bulletsshoot.wav
: A shooting soundsplat.wav
: A sound like a zombie being hit by a bulletOnce you have decided which assets you will use, it is time to add them to the project. These next instructions will assume you are using all the assets supplied in the book's download bundle. Where you are using your own, simply replace the appropriate sound or graphic file with your own, using exactly the same file name that is used in this book:
D:Visual Studio StuffProjectsombieArenaombieArena
.graphics
, sound
, and fonts
.Chapter 6/graphics
into the D:Visual Studio StuffProjectsombieArenaombieArenagraphics
folder.Chapter 6/sound
into the D:Visual Studio StuffProjectsombieArenaombieArenasound
folder.Extract the contents of the zipped download and add the zombiecontrol.ttf
file to the D:Visual Studio StuffProjectsombieArenaombieArenafonts
folder. Now it's time to learn some more C++, so we can start writing the code for Zombie Arena.
18.116.43.124