Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Beginning C++ Game Programming
Beginning C++ Game Programming

Beginning C++ Game Programming: Learn to program with C++ by building fun games , Second Edition

Arrow left icon
Profile Icon John Horton
Arrow right icon
NZ$65.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (10 Ratings)
Paperback Oct 2019 746 pages 2nd Edition
eBook
NZ$46.99 NZ$52.99
Paperback
NZ$65.99
Subscription
Free Trial
Arrow left icon
Profile Icon John Horton
Arrow right icon
NZ$65.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (10 Ratings)
Paperback Oct 2019 746 pages 2nd Edition
eBook
NZ$46.99 NZ$52.99
Paperback
NZ$65.99
Subscription
Free Trial
eBook
NZ$46.99 NZ$52.99
Paperback
NZ$65.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Beginning C++ Game Programming

Chapter 1: C++, SFML, Visual Studio, and Starting the First Game

Welcome to Beginning C++ Game Programming. I will not waste any time in getting you started on your journey to writing great games for the PC using C++ and the OpenGL powered SFML.

This is quite a hefty first chapter, but we will learn absolutely everything we need so that we have the first part of our first game up and running. Here is what we will do in this chapter:

  • Find out about the games we will build
  • Meet C++
  • Find out about Microsoft Visual C++
  • Explore SFML and its relationship with C++
  • Setting up the development environment
  • Plan and prepare for the first game project, Timber!!!
  • Write the first C++ code of this book and make a runnable game that draws a background

The games we will build

This journey will be smooth as we will learn about the fundamentals of the super-fast C++ language one step at a time, and then put this new knowledge to use by adding cool features to the five games we are going to build.

The following are our five projects for this book.

Timber!!!

The first game is an addictive, fast-paced clone of the hugely successful Timberman, which can be found at http://store.steampowered.com/app/398710/. Our game, Timber!!!, will introduce us to all the basics of C++ while we build a genuinely playable game. Here is what our version of the game will look like when we are done and we have added a few last-minute enhancements:

Pong

Pong was one of the first video games to be made, and you can find out about its history here: https://en.wikipedia.org/wiki/Pong. It is an excellent example of how the basics of game object animation and dynamic collision detection work. We will build this simple retro game to explore the concept of classes and object-oriented programming. The player will use the bat at the bottom of the screen and hit the ball back to the top of the screen:

Zombie Arena

Next, we will build a frantic, zombie survival shooter, not unlike the Steam hit Over 9,000 Zombies!, which you can find out more about at http://store.steampowered.com/app/273500/. The player will have a machine gun and must fight off ever-growing waves of zombies. All this will take place in a randomly generated, scrolling world. To achieve this, we will learn about how object-oriented programming allows us to have a large code base (lots of code) that is easy to write and maintain. Expect exciting features such as hundreds of enemies, rapid-fire weaponry, pickups, and a character that can be “leveled up” after each wave:

Thomas was late

The fourth game will be a stylish and challenging single-player and co-op puzzle platformer. It is based on the very popular game Thomas was Alone (http://store.steampowered.com/app/220780/). Expect to learn about cool topics such as particle effects, OpenGL Shaders, and split-screen cooperative multiplayer:

Tip

If you want to play any of the games now, you can do so from the download bundle in the Runnable Games folder. Just double-click on the appropriate .exe file. Note that, in this folder, you can run either the completed games or any game in its partially completed state from any chapter.

Space Invaders ++

The final game will be a Space Invaders clone. In some ways, the game itself is not what is important about this project. The project will be used to learn about game programming patterns. As will become abundantly clear as this book progresses, our code keeps getting longer and more complicated. Each project will introduce one or more techniques for coping with this, but the complexity and length of our code will keep coming back to challenge us, despite these techniques.

The Space Invaders project (called Space Invaders ++) will show us ways in which we can radically reorganize our game code also that we can take control of and properly manage our code once and for all. This will leave you with all the knowledge you need to plan and build deep, complex, and innovative games, without ending up in a tangle of code.

The game will also introduce concepts such as screens, input handlers, and entity-component systems. It will also allow us to learn how to let the player use a gamepad instead of the keyboard and introduce the C++ concepts of smart pointers, casts, assertions, breakpoint debugging, and teach us the most important lesson from the whole book: how to build your own unique games:

Let’s get started by introducing C++, Visual Studio, and SFML!

Meet C++

Now that we know what games we will be building, let’s get started by introducing C++, Visual Studio, and SFML. One question you might have is, why use the C++ language at all? C++ is fast – very fast. What makes this true is the fact that the code that we write is directly translated into machine-executable instructions. These instructions are what make the game. The executable game is contained within a .exe file, which the player can simply double-click to run.

There are a few steps in the process of changing our code into an executable file. First, the preprocessor looks to see if any other code needs to be included within our own code and adds it. Next, all the code is compiled into object files by the compiler program. Finally, a third program, called the linker, joins all the object files into the executable file for our game.

In addition, C++ is well established at the same time as being extremely up to date. C++ is an object-oriented programming (OOP) language, which means we can write and organize our code using well-tested conventions that make our games efficient and manageable. The benefits as well as the necessity of this will reveal themselves as we progress through this book.

Most of this other code that I referred to, as you might be able to guess, is SFML, and we will find out more about SFML in just a minute. The preprocessor, compiler, and linker programs I have just mentioned are all part of the Visual Studio integrated development environment (IDE).

Microsoft Visual Studio

Visual Studio hides away the complexity of preprocessing, compiling, and linking. It wraps it all up into the press of a button. In addition to this, it provides a slick user interface for us to type our code into and manage what will become a large selection of code files and other project assets as well.

While there are advanced versions of Visual Studio that cost hundreds of dollars, we will be able to build all five of our games in the free “Express 2019 for Community” version. This is the latest free version of Visual Studio.

SFML

SFML is the Simple Fast Media Library. It is not the only C++ library for games and multimedia. It is possible to make an argument to use other libraries, but SFML seems to come through for me every time. Firstly, it is written using object-oriented C++. The benefits of object-oriented C++ are numerous, and you will experience them as you progress through this book.

SFML is also easy to get started with and is therefore a good choice if you are a beginner, yet at the same time it has the potential to build the highest-quality 2D games if you are a professional. So, a beginner can get started using SFML and not worry about having to start again with a new language/library as their experience grows.

Perhaps the biggest benefit is that most modern C++ programming uses OOP. Every C++ beginner’s guide I have ever read uses and teaches OOP. OOP is the future (and the now) of coding in almost all languages, in fact. So why, if you’re learning C++ from the beginning, would you want to do it any other way?

SFML has a module (code) for just about anything you would ever want to do in a 2D game. SFML works using OpenGL, which can also make 3D games. OpenGL is the de facto free-to-use graphics library for games when you want it to run on more than one platform. When you use SFML, you are automatically using OpenGL.

SFML allows you to create the following:

  • 2D graphics and animations, including scrolling game worlds.
  • Sound effects and music playback, including high-quality directional sound.
  • Input handling with a keyboard, mouse, and gamepad.
  • Online multiplayer features.
  • The same code can be compiled and linked on all major desktop operating systems, and mobile as well!.

Extensive research has not uncovered any more suitable ways to build 2D games for PC, even for expert developers and especially if you are a beginner and want to learn C++ in a fun gaming environment.

In the sections that follow, we will set up the development environment, beginning with a discussion on what to do if you are using Mac or Linux operating systems.

Setting up the development environment

Now that you know a bit more about how we will be making games, it is time to set up a development environment so we can get coding.

What about Mac and Linux?

The games that we will be making can be built to run on Windows, Mac, and Linux! The code we use will be identical for each platform. However, each version does need to be compiled and linked on the platform for which it is intended, and Visual Studio will not be able to help us with Mac and Linux.

It would be unfair to say, especially for complete beginners, that this book is entirely suited for Mac and Linux users. Although, I guess, if you are an enthusiastic Mac or Linux user and you are comfortable with your operating system, you will likely succeed. Most of the extra challenges you will encounter will be in the initial setup of the development environment, SFML, and the first project.

To this end, I can highly recommend the following tutorials, which will hopefully replace the next 10 pages (approximately), up to the Planning Timber!!! section, when this book will become relevant to all operating systems.

For Linux, read this to replace the next few sections: https://www.sfml-dev.org/tutorials/2.5/start-linux.php.

On Mac, read this tutorial to get started: https://www.sfml-dev.org/tutorials/2.5/start-osx.php.

Installing Visual Studio 2019 Community edition

To start creating a game, we need to install Visual Studio 2019. Installing Visual Studio can be almost as simple as downloading a file and clicking a few buttons. I will walk you through the installation process a step at a time.

Important note

Note that, over the years, Microsoft is likely to change the name, appearance, and download page that’s used to obtain Visual Studio. They are likely to change the layout of the user interface and make the instructions that follow out of date. However, the settings that we configure for each project are fundamental to C++ and SFML, so careful interpretation of the instructions that follow in this chapter will likely be possible, even if Microsoft does something radical to Visual Studio. Anyway, at the time of writing, Visual Studio 2019 has been released for just two weeks, so hopefully this chapter will be up to date for a while. If something significant does happen, then I will add an up-to-date tutorial on http://gamecodeschool.com as soon as I find out about it.

Let’s get started with installing Visual Studio:

  1. The first thing you need is a Microsoft account and login details. If you have a Hotmail or MSN email address, then you already have one. If not, you can sign up for a free one here: https://login.live.com/.
  2. The next step is to visit https://visualstudio.microsoft.com/vs/ and find the download link for Community 2019. This is what it looks like at the time of writing:
  3. Save the file to your computer.
  4. When the download completes, run the download by double-clicking on it. My file, at the time of writing, was called vs_community__33910147.1551368984.exe. Yours will be different based on the current version of Visual Studio.
  5. After giving permission for Visual Studio to make changes to your computer, you will be greeted with the following window. Click Continue:
  6. Wait for the installer program to download some files and set up the next stage of the installation. Shortly, you will be presented with the following window:
  7. If you want to choose a new location to install Visual Studio, locate the Change option and configure the install location. The simplest thing to do is leave the file at the default location chosen by Visual Studio. When you are ready, locate the Desktop development with C++ option and select it.
  8. Next, click the Install button. Grab some refreshments as this step might take a while.
  9. When the process completes, you can close all open windows, including any that prompt you to start a new project, as we are not ready to start coding until we have installed SFML.

Now, we are ready to turn our attention to SFML.

Setting up SFML

This short tutorial will guide you through downloading the SFML files that allow us to include the functionality contained in the library in our projects. In addition, we will see how we can use the SFML DLL files that will enable our compiled object code to run alongside SFML. To set up SFML, follow these steps:

  1. Visit this link on the SFML website: http://www.sfml-dev.org/download.php. Click on the button that says Latest stable version, as shown here:
  2. By the time you read this book, the latest version will almost certainly have changed. This won’t matter as long as you do the next step just right. We want to download the 32-bit version of Visual C++ 2017. This might sound counter-intuitive because we have just installed Visual Studio 2019 and you probably (most commonly) have a 64-bit PC. The reason we chose to download the 32-bit version is that Visual C++ 2017 is part of Visual Studio 2019 (Visual Studio does more than C++) and we will be building games in 32-bit so that they can run on both 32- and 64-bit machines. Click the Download button that’s shown in the following screenshot:
  3. When the download completes, create a folder at the root of the same drive where you installed Visual Studio and name it SFML. Also, create another folder at the root of the drive where you installed Visual Studio and call it VS Projects.
  4. Finally, unzip the SFML download. Do this on your desktop. When unzipping is complete, you can delete the .zip folder. You will be left with a single folder on your desktop. Its name will reflect the version of SFML that you downloaded. Mine is called SFML-2.5.1-windows-vc15-32-bit. Your filename will likely reflect a more recent version. Double-click this folder to see its contents, then double-click again into the next folder (mine is called SFML-2.5.1). The following screenshot shows what my SFML-2.5.1 folder’s content looks like. Yours should look the same:
  5. Copy the entire contents of this folder and paste all the files and folders into the SFML folder that you created in Step 3. For the rest of this book, I will refer to this folder simply as “your SFML folder”.

Now, we are ready to start using C++ and SFML in Visual Studio.

Creating a new project

As setting up a project is a fiddly process, we will go through it step by step so that we can start getting used to it:

  1. Start Visual Studio in the same way you start any app: by clicking on its icon. The default installation options will have placed a Visual Studio 2019 icon in the Windows start menu. You will see the following window:
  2. Click on the Create a new project button, as highlighted in the preceding screenshot. You will see the Create a new project window, as shown in the following screenshot:
  3. In the Create a new project window, we need to choose the type of project we will be creating. We will be creating a console app, so select Console App, as highlighted in the preceding screenshot, and click the Next button. You will then see the Configure your new project window. This following screenshot shows the Configure your new project window after the next three steps have been completed:
  4. In the Configure your new project window, type Timber in the Project name field. Note that this causes Visual Studio to automatically configure the Solution name field to the same name.
  5. In the Location field, browse to the VS Projects folder that we created in the previous tutorial. This will be the location that all our project files will be kept.
  6. Check the option to Place solution and project in the same directory.
  7. Note that the preceding screenshot shows what the window looks like when the previous three steps have been completed. When you have completed these steps, click Create. The project will be generated, including some C++ code. This following screenshot shows where we will be working throughout this book:
  8. We will now configure the project to use the SFML files that we put in the SFML folder. From the main menu, select Project | Timber properties…. You will see the following window:

Tip

In the preceding screenshot, the OK, Cancel, and Apply buttons are not fully formed. This is likely a glitch with Visual Studio not handling my screen resolution correctly. Yours will hopefully be fully formed. Whether your buttons appear like mine do or not, continuing with the tutorial will be the same.

Next, we will begin to configure the project properties. As these steps are quite intricate, I will cover them in a new list of steps.

Configuring the project properties

At this stage, you should have the Timber Property Pages window open, as shown in the preceding screenshot at the end of the previous section. Now, we will begin to configure some properties while using the following annotated screenshot for guidance:

We will add some fairly intricate and important project settings in this section. This is the laborious part, but we will only need to do this once per project. What we need to do is tell Visual Studio where to find a special type of code file from SFML. The special type of file I am referring to is a header file. Header files are the files that define the format of the SFML code so that when we use the SFML code, the compiler knows how to handle it. Note that the header files are distinct from the main source code files and they are contained in files with the .hpp file extension. All this will become clearer when we eventually start adding our own header files in the second project. In addition, we need to tell Visual Studio where it can find the SFML library files. In the Timber Property Pages window, perform the following three steps, which are numbered in the preceding screenshot:

  1. First (1), select All Configurations from the Configuration: drop down.
  2. Second (2), select C/C++ then General from the left-hand menu.
  3. Third (3), locate the Additional Include Directories edit box and type the drive letter where your SFML folder is located, followed by \SFML\include. The full path to type, if you located your SFML folder on your D drive, is as shown in the preceding screenshot; that is, D:\SFML\include. Vary your path if you installed SFML on a different drive.
  4. Click Apply to save your configurations so far.
  5. Now, still in the same window, perform these steps, which refer to the following annotated screenshot. First (1), select Linker and then General.
  6. Now, find the Additional Library Directories edit box (2) and type the drive letter where your SFML folder is, followed by \SFML\lib. So, the full path to type if you located your SFML folder on your D drive is, as shown in the following screenshot, D:\SFML\lib. Vary your path if you installed SFML to a different drive:
  7. Click Apply to save your configurations so far.
  8. Finally, for this stage, still in the same window, perform these steps, which refer to the following annotated screenshot. Switch the Configuration: drop down (1) to Debug as we will be running and testing our games in debug mode.
  9. Select Linker and then Input (2).
  10. Find the Additional Dependencies edit box (3) and click into it at the far-left-hand side. Now, copy and paste/type the following: sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-network-d.lib;sfml-audio-d.lib; at the indicated place. Be extra careful to place the cursor exactly in the right place and not to overwrite any of the text that is already there.
  11. Click OK:
  12. Click Apply and then OK.

Phew; that’s it! We have successfully configured Visual Studio and can move on to planning the Timber!!! project.

Planning Timber!!!

Whenever you make a game, it is always best to start with a pencil and paper. If you don’t know exactly how your game is going to work on the screen, how can you possibly make it work in code?

Tip

At this point, if you haven’t already, I suggest you go and watch a video of Timberman in action so that you can see what we are aiming for. If you feel your budget can stretch to it, then grab a copy and give it a play. It is often on sale for under $1 on Steam: http://store.steampowered.com/app/398710/.

The features and objects of a game that define the gameplay are known as the mechanics. The basic mechanics of the game are as follows:

  • Time is always running out.
  • You can get more time by chopping the tree.
  • Chopping the tree causes the branches to fall.
  • The player must avoid the falling branches.
  • Repeat until time runs out or the player is squished.

Expecting you to plan the C++ code at this stage is obviously a bit silly. This is, of course, the first chapter of a C++ beginner’s guide. We can, however, take a look at all the assets we will use and an overview of what we will need to make our C++ code do.

Take a look at this annotated screenshot of the game:

You can see that we have the following features:

  • The player’s score: Each time the player chops a log, they will get one point. They can chop a log with either the left or the right arrow (cursor) key.
  • Player character: Each time the player chops, they will move to/stay on the same side of the tree relative to the cursor key they use. Therefore, the player must be careful which side they choose to chop on.
  • When the player chops, a simple axe graphic will appear in the player character’s hands.
  • Shrinking time-bar: Each time the player chops, a small amount of time will be added to the ever-shrinking time-bar.
  • The lethal branches: The faster the player chops, the more time they will get, but also the faster the branches will move down the tree and therefore the more likely they are to get squished. The branches spawn randomly at the top of the tree and move down with each chop.
  • When the player gets squished – and they will get squished quite regularly – a gravestone graphic will appear.
  • The chopped log: When the player chops, a chopped log graphic will whiz off, away from the player.
  • Just for decoration: There are three floating clouds that will drift at random heights and speeds, as well as a bee that does nothing but fly around.
  • The background: All this takes place on a pretty background.

So, in a nutshell, the player must frantically chop to gain points and avoid running out of time. As a slightly perverse, but fun consequence, the faster they chop, the more likely their squishy demise is.

We now know what the game looks like, how it is played, and the motivation behind the game mechanics. Now, we can go ahead and start building it. Follow these steps:

  1. Now, we need to copy the SFML .dll files into the main project directory. My main project directory is D:\VS Projects\Timber. It was created by Visual Studio in the previous tutorial. If you put your VS Projects folder somewhere else, then perform this step there instead. The files we need to copy into the project folder are located in your SFML\bin folder. Open a window for each of the two locations and highlight all the files in the SFML\bin folder, as shown in the following screenshot:
  2. Now, copy and paste the highlighted files into the project folder, that is, D:\VS Projects\Timber.

The project is now set up and ready to go. You will be able to see the following screen. I have annotated this screenshot so you can start familiarizing yourself with Visual Studio. We will revisit all these areas, and others, soon:

Your layout might look slightly different to what’s shown in the preceding screenshot because the windows of Visual Studio, like most applications, are customizable. Take the time to locate the Solution Explorer window on the right and adjust it to make its content nice and clear, like it is in the previous screenshot.

We will be back here soon to start coding. But first, we will explore the project assets we will be using.

The project assets

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

  • 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 sounds that are required for this game are included in the download bundle for this book. 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 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 or acquire them for yourself.

Outsourcing the assets

There are a number of websites that allow you to contract artists, sound engineers, and even programmers. One of the biggest is Upwork (www.upwork.com). You can join this site for free and post your jobs. You will 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, however, that there are 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 such as Freesound (www.freesound.org), but often the licence 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 with as you like.

Adding the assets to the project

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 that are supplied in this 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 filename:

  1. Browse to the project folder, that is, D:\VS Projects\Timber.
  2. Create three new folders within this folder and name them graphics, sound, and fonts.
  3. From the download bundle, copy the entire contents of Chapter 1/graphics into the D:\VS Projects\Timber\graphics folder.
  4. From the download bundle, copy the entire contents of Chapter 1/sound into the D:\VS Projects\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:\VS Projects\Timber\fonts folder.

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

Exploring the assets

The graphical assets make up the parts of the scene that is our Timber!!! game. If you take a look at the graphical assets, it should be clear where in our game they will be used:

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

  • chop.wav: A sound that is a bit like an axe (a retro axe) chopping a tree
  • death.wav: A sound a bit like a retro “losing” sound
  • out_of_time.wav: A sound that plays when the player loses by running out of time, as opposed to being squashed

We have seen all the assets, including the graphics, so now we will have a short discussion related to the resolution of the screen and how we position the graphics on it.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn game development and C++ with a fun, example-driven approach
  • Build clones of popular games such as Timberman, Zombie Survival Shooter, a co-op puzzle platformer, and Space Invaders
  • Discover tips to expand your finished games by thinking critically, technically, and creatively

Description

The second edition of Beginning C++ Game Programming is updated and improved to include the latest features of Visual Studio 2019, SFML, and modern C++ programming techniques. With this book, you’ll get a fun introduction to game programming by building five fully playable games of increasing complexity. You’ll learn to build clones of popular games such as Timberman, Pong, a Zombie survival shooter, a coop puzzle platformer and Space Invaders. The book starts by covering the basics of programming. You’ll study key C++ topics, such as object-oriented programming (OOP) and C++ pointers, and get acquainted with the Standard Template Library (STL). The book helps you learn about collision detection techniques and game physics by building a Pong game. As you build games, you’ll also learn exciting game programming concepts such as particle effects, directional sound (spatialization), OpenGL programmable shaders, spawning objects, and much more. Finally, you’ll explore game design patterns to enhance your C++ game programming skills. By the end of the book, you’ll have gained the knowledge you need to build your own games with exciting features from scratch

Who is this book for?

This book is perfect for you if you have no C++ programming knowledge, you need a beginner-level refresher course, or you want to learn how to build games or just use games as an engaging way to learn C++. Whether you aspire to publish a game (perhaps on Steam) or just want to impress friends with your creations, you’ll find this book useful.

What you will learn

  • Set up your game development project in Visual Studio 2019 and explore C++ libraries such as SFML
  • Explore C++ OOP by building a Pong game
  • Understand core game concepts such as game animation, game physics, collision detection, scorekeeping, and game sound
  • Use classes, inheritance, and references to spawn and control thousands of enemies and shoot rapid-fire machine guns
  • Add advanced features to your game using pointers, references, and the STL
  • Scale and reuse your game code by learning modern game programming design patterns
Estimated delivery fee Deliver to New Zealand

Standard delivery 10 - 13 business days

NZ$20.95

Premium delivery 5 - 8 business days

NZ$74.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 31, 2019
Length: 746 pages
Edition : 2nd
Language : English
ISBN-13 : 9781838648572
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to New Zealand

Standard delivery 10 - 13 business days

NZ$20.95

Premium delivery 5 - 8 business days

NZ$74.95
(Includes tracking information)

Product Details

Publication date : Oct 31, 2019
Length: 746 pages
Edition : 2nd
Language : English
ISBN-13 : 9781838648572
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 261.97
C++ Game Development By Example
NZ$56.99
Beginning C++ Game Programming
NZ$65.99
Modern C++ Programming Cookbook
NZ$138.99
Total NZ$ 261.97 Stars icon

Table of Contents

24 Chapters
Chapter 1: C++, SFML, Visual Studio, and Starting the First Game Chevron down icon Chevron up icon
Chapter 2: Variables, Operators, and Decisions – Animating Sprites Chevron down icon Chevron up icon
Chapter 3: C++ Strings and SFML Time – Player Input and HUD Chevron down icon Chevron up icon
Chapter 4: Loops, Arrays, Switches, Enumerations, and Functions – Implementing Game Mechanics Chevron down icon Chevron up icon
Chapter 5: Collisions, Sound, and End Conditions – Making the Game Playable Chevron down icon Chevron up icon
Chapter 6: Object-Oriented Programming – Starting the Pong Game Chevron down icon Chevron up icon
Chapter 7: Dynamic Collision Detection and Physics – Finishing the Pong Game Chevron down icon Chevron up icon
Chapter 8: SFML Views – Starting the Zombie Shooter Game Chevron down icon Chevron up icon
Chapter 9: C++ References, Sprite Sheets, and Vertex Arrays Chevron down icon Chevron up icon
Chapter 10: Pointers, the Standard Template Library, and Texture Management Chevron down icon Chevron up icon
Chapter 11: Collision Detection, Pickups, and Bullets Chevron down icon Chevron up icon
Chapter 12: Layering Views and Implementing the HUD Chevron down icon Chevron up icon
Chapter 13: Sound Effects, File I/O, and Finishing the Game Chevron down icon Chevron up icon
Chapter 14: Abstraction and Code Management – Making Better Use of OOP Chevron down icon Chevron up icon
Chapter 15: Advanced OOP – Inheritance and Polymorphism Chevron down icon Chevron up icon
Chapter 16: Building Playable Levels and Collision Detection Chevron down icon Chevron up icon
Chapter 17: Sound Spatialization and the HUD Chevron down icon Chevron up icon
Chapter 18: Particle Systems and Shaders Chevron down icon Chevron up icon
Chapter 19: Game Programming Design Patterns – Starting the Space Invaders ++ Game Chevron down icon Chevron up icon
Chapter 20: Game Objects and Components Chevron down icon Chevron up icon
Chapter 21: File I/O and the Game Object Factory Chevron down icon Chevron up icon
Chapter 22: Using Game Objects and Building a Game Chevron down icon Chevron up icon
Chapter 23: Before You Go... Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(10 Ratings)
5 star 60%
4 star 10%
3 star 20%
2 star 10%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




J Anderson Jan 27, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The method the author uses may not be for everyone, but for me, it's exactly what I've been looking for.I picked up C++ a few months ago in order to get to a point in which I could make my own game(s), or to get a job in game programming. I've learned a lot about C++ but also much about myself as a learner in my 30s, trying to pick something up that is, essentially, another language. I've read through the first 15-25% of multiple text books since having started. I enjoy learning new programming concepts, and getting further into the knowledge of C++, but most of the resources I'd found were either [A] not actually teaching game programming but were teaching general programming with C++, or [B] the "games" being taught in these books were command line text-based games, nothing all that directly applicable to a rendered 2D/3D game that I wanted to create from the very beginning.This book starts right off the bat getting the reader in with very simple concepts to get a window to open and pop up, which is far more than any of the other books I'd read into had done. It then teaches you directly how to use SFML to attach textures to sprites, and then render said sprites on the screen.One thing that might be a tad intimidating is that the author introduces classes VERY early, like within the first few pages of the book, but it is a necessity and, so long as the reader can somewhat grasp that a class is like a template, and an object is a single usage of said template, the reader will be able to follow along. The book is challenging but being able to step-by-step read how he breaks down each bit of code is enough to get me over those challenging parts.I've just completed Chapter 5 and the first full game engine the author walks you through coding. To be introduced to beginner concepts by building a game engine is exactly what I'd been looking for this entire time but hadn't found. The author walks the reader through every single line of code, explains what it does and why it's there. It's really wonderful. I've learned so much more relevant information in this book in the first 5 chapters than everything I'd read on C++ prior, and I'm actually excited to continue.I truly am grateful for this book. Packt.com was having a sale so I got the ebook for 5 bucks, but this is worth so much more. I'll be purchasing the print version soon enough to support the author.If you're interested in actual game development, game engine programming, and you're a bit of a noob, you need to check this book out. I absolutely love it. It's exactly what I've been looking for.
Amazon Verified review Amazon
R. Tkatch Jul 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is simple because the author is teaching someone that knows nothing about c++ including basic data structures. However, for this is a perfect approach even for the one who knows this because it gives the student a simple example to make into more refined code. This gives an example but allows one to put their approach to it. I have only gotten a bit into the book. I will update this review when I get closer to the end.
Amazon Verified review Amazon
JKG Feb 24, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
C++ fundamentals are laid out in an easy to read and easy to follow format. Plenty of practice exercises to reinforce the material.
Amazon Verified review Amazon
satcom4fun Mar 13, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really liked the incremental approach to learning C++ using games. The final game architecture is amazing and shows how to abstract game components into classes. Just what I needed.
Amazon Verified review Amazon
Dawit Mar 02, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is pretty pog!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela