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

Project assets


Assets are anything you need to make your game. In our case the assets include:

  • A font for the writing on the screen

  • Sound effects for different actions such as chopping, dying, and running out of time

  • Graphics for the character, background, branches, and other game objects

All the graphics and sound required for the game are included in the download bundle. They can be found in the Chapter 1/graphics and Chapter 1/sound folders as appropriate.

The font that is required has not been supplied. This is because I wanted to avoid any possible ambiguity regarding licensing. 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.

Outsourcing assets

There are a number of websites that allow you to contract artists, sound engineers, and even programmers. One of the biggest is the www.upwork.com. You can join this site for free and post your jobs. You need to write a clear explanation of your requirements as well as state how much you are prepared to pay. Then you will probably get a good selection of contractors bidding to do the work. Be aware, there is a lot of unqualified contractors whose work might be disappointing, but if you choose carefully you will likely find a competent, enthusiastic, and great value person or company to do the job.

Making your own sound FX

Sound effects can be downloaded for free from sites like www.freesound.org but often the license won't allow you to use them if you are selling your game. Another option is to use an open source software called BFXR from www.bfxr.net, which can help you generate lots of different sound effects that are yours to keep and do as you like with.

Adding assets to the project

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

  1. Browse to the Visual D:\Visual Studio Stuff\Projects\Timber\Timber.

  2. Create three new folders within this folder and name them as graphics, sound, and fonts.

  3. From the download bundle, copy the entire contents of Chapter 1/graphics into the D:\Visual Studio Stuff\Projects\Timber\Timber\graphics folder.

  4. From the download bundle, copy the entire contents of Chapter 1/sound into the D:\Visual Studio Stuff\Projects\Timber\Timber\sound folder.

  5. Now visit: http://www.1001freefonts.com/komika_poster.font in your web browser and download the Komika Poster font.

  6. Extract the contents of the zipped download and add the KOMIKAP_.ttf file to the D:\Visual Studio Stuff\Projects\Timber\Timber\fonts folder.

Let's take a look at these assets, especially the graphics, so we can better visualize what is happening when we use them in our C++ code.

Exploring assets

Graphical assets form the individual parts of the screen in our Timber!!! game. Take a look at the graphical assets and it should be clear where, in our game, they will be used.

The sound files are all .wav format. These are files containing the sound effects that we will play at certain events throughout the game. They were all generated using BFXR. They are:

  • chop.wav: A sound that is a bit like an ax (a retro ax) chopping a tree

  • death.wav: A sound a bit like a retro "losing" sound.

  • out_of_time.wav: Plays when the player loses by running out of time, as opposed to being squashed