Explore modern game development and programming techniques to build 5 complete, playable games using C++ and its popular libraries
ISBN: 97818386485729781838647650
Paperback: 700 pages
Feature list
- Learn the basics of C++ such as variables and loops
- Animate game objects, respond to collisions, keep score, play sound effects
- Use classes, inheritance, and references to spawn and control thousands of enemies
- Learn to shoot with a rapid-fire machine gun, and realize random scrolling game-worlds
- Use pointers, references, and Standard Template Library to add various features
- Reuse code to make different games
Details
With this improved and extended 2nd edition, 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.
By the end of this book, you’ll have all the knowledge you need to get started with your game development and programming career with C++ and its libraries.
Features
- This book offers a fun way to learn modern C++ programming while building 5 exciting 2D games
- Immerse yourself in building a wide variety of desktop games that gradually increase in complexity
- Packed with suggestions to expand your finished games that will make you think critically, technically, and creatively
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 as well as 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.
Errata? In chapter 6, page 166 a “using namespace sf;” directive is used in the header file, which I’m told is not a good idea. The directive is also missing from the Bat.cpp file on page 169. I’m enjoying the book and already make my own two-player Pong game. Regards.
In the Player::update function in Zombie Arena where you calculate the angle the player is facing was giving me a C26451 Arithmetic Overflow warning. I changed the * 180 to * 180.0 and the warning went away.
Thanks James. I’ll leave this comment here to help others. And add to to the errata for the next edition. Thanks again, John
A few of us are having an issue on macOS, where without the apparently required event loop (), the game window never opens. It’s mentioned on this page: https://www.sfml-dev.org/tutorials/2.5/window-window.php
There’s a discussion about it here: https://github.com/SFML/SFML/issues/1677
On page 152 you mention an enhanced version of Timber.
“To see the code for these enhancements, take a look in the Timber Enhanced
Version folder of the download bundle.”
After downloading from Pakct website there is not a folder with the enhanced version. Where can I get this from please as you mention optimised code for the clouds?
Hi David,
Thanks for your mail and for reading my book. I have just looked at the code on github and it is missing. The exe is in the runnable folder. I am stuck in bed with a minor ailment at the moment so the solution that should work would be to use the code from the first version of the book. This should be the same apart from some header differences and also I think the text class is different. However, the use of arrays for clouds etc and the enhanced code should be the same.
Here is the link. https://github.com/PacktPublishing/Beginning-Cpp-Game-Programming/tree/master/Proj_01_Codes/Timber%20Enhanced%20Version/code
Hope this helps,
John
Dear John,
I have I’ve notice that in page 317 in the book when I type window.setMouseCursorVisible(true) both the crosshair and mouse display on my game but if set it to false it shows just he crosshair like in the pictures.
And also on page 323 I was having a really hard time to compile the game, the compiler was giving an error “the qualified named name is not allowed in member declaration” on the line Pickup::Pickup(int type); so I changed it to Pickup(int type)” and it actually compile with no errors.
I’m looking forward to finishing up the book so I can star to make my own games, thank you very much for the book.
Thanks Armando. Well done for beating the problem. This info will probably be useful to others.
Hi John the repository here https://github.com/PacktPublishing/Beginning-C-Game-Programming is empty where can I download the source codes of the book?
Hi there,
I think this is the correct URL
https://github.com/PacktPublishing/Beginning-Cpp-Game-Programming-Second-Edition
In the Beginning C++ Game Programming book, on page31, in the example code your using the namespace sf. This is undefined when compiled. I looked in the Graphics.hpp file and it is not declared there. Is there something I am missing?
Dear John,
I can not seem to get the player graphic to draw on the screen in the Zombie Arena game? All I get is a blank black screen.
I am stuck with one error in chapter 16: If I wait long enough (30sec in default example code) the level 1 will end and level 2 will start (and so on, wait level 2 time to run out, and level 3 will start). This isn’t supposed to happen? I mean, i tested chapter 16 exe that was in the bundle, and it doesn’t happen. Which makes sense, you are not supposed to go to next level by waiting: time limit should make player(s) to restart the level they are in or level 1. I tested this on example code and get the same results. And following the code it does indeed look like that when time runs out there is a nextLevel++ and it’s not that hard to figure out I suppose. but I just would like to see the official way to do it?
Dear John! I read above Armando L October 8, 2021 about the solution to the error. But I didn’t understand what needed to change. In Pickup.h at line 38 need Pickup::Pickup(int type); replace with Pickup::Pickup(int type)”;
So you can add only quotation marks ( ” ) before ( ; ) is it correct ?
I think Armando is saying change
Pickup::Pickup(int type)
to
Pickup(int type)
Dear John,
First thanks for your book, I’m learning a lot. I’ve entered all the code for Space Invaders ++ but there seems to be a small part missing and I can’t figure it out as I’m new to component-based systems: Could you give me the code?
in GameInputHandler.h the shared pointers m_PUC and m_PTC are declared but they are not initialised anywhere, and I think this is why the game crashes. Where and how should I do this?
Apologies – I found the answer in the downloaded source code.
I have just finished reading the Kindle version of “Beginning C++ Game Programming” 2nd edition by John Horton, purchased from Amazon.
I very much enjoyed the book, but I have one question that I have not been able to resolve, even after extensive ‘Googling’ (perhaps I am not formulating the query correctly). The question relates to the overriding of various virtual functions. In the following header files:
LevelManager.h
ScreenManager.h
BulletUpdateComponent.h
ColliderComponent.h
GraphicsComponent.h
InvaderUpdateComponent.h
PlayerUpdateComponent.h
RectColliderComponent.h
StandardGraphicsComponent.h
TransformComponent.h
UpdateComponent.h
GameScreen.h
There are various overrides for inherited virtual functions. Most, but not all, the functions are qualified by the class name in which the virtual function is first declared. For example, in ScreenManager.h, the ScreenManager class inherits from the ScreenManagerRemoteControl class and overrides:
virtual void SwitchScreens(std::string screenToSwitchTo) = 0;
virtual void loadLevelInPlayMode(std::string screenToLoad) = 0;
virtual std::vector& getGameObjects() = 0;
virtual GameObjectSharer& shareGameObjectSharer() = 0;
The first three overriden functions in ScreenManager.h have the function names qualified by the ScreenManagerRemoteControl class:
void ScreenManagerRemoteControl::SwitchScreens(string screenToSwitchTo)
{
m_CurrentScreen = “” + screenToSwitchTo;
m_Screens[m_CurrentScreen]->initialise();
}
void ScreenManagerRemoteControl::loadLevelInPlayMode(string screenToLoad)
{
m_LevelManager.getGameObjects().clear();
m_LevelManager.
loadGameObjectsForPlayMode(screenToLoad);
SwitchScreens(“Game”);
}
vector& ScreenManagerRemoteControl::getGameObjects()
{
return m_LevelManager.getGameObjects();
}
The fourth function, however, does not i.e.:
GameObjectSharer& shareGameObjectSharer()
{
return m_LevelManager;
}
I’ve noticed that if I remove all class name qualifiers from all the headers, the game still compiles and runs.
My question is: under what circumstances do the inherited functions need to be qualified by the original class names?