In this chapter, we will take a first look at the final project of the book. The project will have advanced features such as directional sound, which comes out of the speakers relative to the position of the player. It will also have split screen cooperative gameplay. In addition, this project will introduce the concept of Shaders, which are programs written in another language that run directly on the graphics card. By the end of Chapter 16, Extending SFML Classes, Particle Systems, and Shaders, you will have a fully functioning multiplayer platform game built in the style of the hit classic Thomas Was Alone.
This chapter's main focus will be getting the project started—in particular, exploring how the code will be structured to make better use of OOP. The following topics will be covered:
At this point, if you haven't already, I would suggest you go and watch a video of Thomas Was Alone at http://store.steampowered.com/app/220780/. Notice the really simple but aesthetically excellent graphics. The video also shows a variety of gameplay challenges such as using the character's different attributes (height, jump, power, and so on). To keep our game simple without losing the challenge, we will have fewer puzzle features than Thomas Was Alone, but will have the additional challenge of creating the need for two players to play cooperatively. Just to make sure the game is not too easy, we will also make the players race against the clock, hence why the name of our game is Thomas Was Late.
Our game will not be nearly as advanced as the masterpiece that we are attempting to emulate, but it will have a good selection of exciting gameplay features:
Take a look at this annotated screenshot of the game to see some of the features in action and the components/assets that make up the game:
Let's look at each of those features and describe a few more:
background.png
file (shown later in this chapter), you will see it is quite different. We will use OpenGL shader effects in Chapter 16, Extending SFML Classes, Particle Systems, and Shaders, to achieve the moving—almost bubbling—effect in the background.All those features warrant a few more screenshots so we can keep the finished product in mind as we write the C++ code.
The following screenshot shows Thomas and Bob arriving at a fire pit that Bob has no chance of jumping over without help:
The following screenshot shows Bob and Thomas collaborating to clear a precarious jump:
The following screenshot shows how we can design puzzles where a "leap of faith" is required in order to reach the goal:
The following screenshot demonstrates how we can design oppressive cave systems of almost any size. We can also devise levels where Bob and Thomas are forced to split up and go different routes:
Creating the Thomas Was Late project is the same as the other two projects. Just follow these straightforward steps in Visual Studio:
TWL
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 TWLTWL
. This folder was created by Visual Studio in the previous step. If you put your Projects
folder somewhere else, perform this step there instead. The files we need to copy into the project
folder are located in your SFMLin
folder. Open a window for each of the two locations and highlight the required .dll
files.The project is now set up and ready to go.
The assets in this project are even more numerous and diverse than the Zombie Arena game. As usual, the assets include a font for the writing on the screen, sound effects for different actions such as jumping, reaching the goal, or the distant roar of fire, and, of course, graphics for Thomas and Bob as well as a sprite sheet for all the background tiles.
All the assets required for the game are included in the download bundle. They can be found in the Chapter 12/graphics
and Chapter 12/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.
In addition to the graphics, sound, and fonts that we have come to expect, this game has two new asset types. They are level design files and GLSL shader programs. Let's find out about each of them next.
Levels are all created in a text file. By using the numbers 0 through 3, we can build level designs to challenge players. All the level designs are in the levels folder in the same directory as the other assets. Feel free to take a peek at one now, but we will look at them in detail in Chapter 14, Building Playable Levels and Collision Detection.
In addition to these level design assets, we have a special type of graphical asset, called shaders.
Shaders are programs written in GLSL (Graphics Library Shading Language). Don't worry about having to learn another language, as we don't need to get too in-depth to take advantage of shaders. Shaders are special, as they are entire programs, separate from our C++ code, which are executed by the GPU each and every frame. In fact, some of these shader programs are run every frame, for every pixel! We will find out more details in Chapter 16, Extending SFML Classes, Particle Systems, and Shaders. If you can't wait that long, take a look at the files in the Chapter 12/shaders
folder of the download bundle.
The graphical assets make up the parts of the scene of our game. Take a look at the graphical assets and it should be clear where in our game they will be used:
If the tiles on the tiles_sheet
graphic look a little different to the screenshots of the game, this is because they are partly transparent and the background showing through changes them a little. If the background graphic looks totally different to the actual background in the game screenshots, that is because the shader programs we will write will manipulate each and every pixel, each and every frame, to create a kind of "molten" effect.
The sound files are all .wav
format. These are files that contain the sound effects we will play at certain events throughout the game. They are as follows:
fallinfire.wav
: A sound that will be played when the player's head goes into fire and the player has no chance of escape.fallinwater.wav
: Water has the same end effect as fire: death. This sound effect notifies the player they need to start from the beginning of the level.fire1.wav
: This sound effect is recorded in mono. It will be played at different volumes based on the player's distance from fire tiles, and from different speakers based on whether the player is to the left or the right of the fire tile. Clearly, we will need to learn a few more tricks to implement this functionality.jump.wav
: A pleasing (slightly predictable) whooping sound for when the player jumps.reachgoal.wav
: A pleasing victory sound for when the player (or players) gets both characters (Thomas and Bob) to the goal tile.The sound effects are very straightforward and you can easily create your own. If you intend to replace the fire1.wav
file, be sure to save your sound in a mono (not stereo) format. The reasons for this will be explained in Chapter 15, Sound Spacialization and HUD.
Once you have decided which assets you will use, it is time to add them to the project. The following 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 chosen file, using exactly the same filename:
D:Visual Studio StuffProjectsTWLTWL
directory.graphics
, sound
, fonts
, shaders
, and levels
.Chapter 12/graphics
into the D:Visual Studio StuffProjectsTWLTWLgraphics
folder.Chapter 12/sound
into the D:Visual Studio StuffProjectsTWLTWLsound
folder.Roboto-Light.ttf
file to the D:Visual Studio StuffProjectsTWLTWLfonts
folder.Chapter 12/levels
into the D:Visual Studio StuffProjectsTWLTWLlevels
folder.Chapter 12/shaders
into the D:Visual Studio StuffProjectsTWLTWLshaders
folder.Now that we have a new project, along with all the assets we will need for the entire project, we can talk about how we will structure the game engine code.
3.14.131.212