Are you looking to learn C++ from scratch and simultaneously build stunning and interactive games?
Explore this Learning Path and you'll get what you're looking for. Start as an amateur and rise as a pro by taking this Learning Path.
This Learning Path is a fun journey to the world of game programming starting from the very basics of C++ such as OOP, pointers, introduction to the Standard Template Library, and finally building OpenGL-powered SFML fully-playable complex games.
These games are an addictive frantic two-button tapper, a multi-level zombie survival shooter, and a split-screen multiplayer puzzle-platformer.
You will explore exciting game programming concepts such as particle effects, directional sound, OpenGL programmable Shaders, spawning thousands of objects, and more.
Packt’s Video Learning Paths are a series of individual video products put together in a logical and stepwise manner such that each video builds on the skills learned in the video before it.
John Horton is a coding and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles about programming, especially for beginners. He is the founder of Game Code School , which is dedicated to helping complete beginners get started with coding using the language and platform that is best suited for them. John sincerely believes that anyone can learn to code and that everybody has a game or an app inside of them, and that they just need to do enough work to bring it out.
SFML has the potential to build the highest-quality 2D games. So a beginner can start using SFML and not worry about having to start again with a new language/library as their experience grows. Let's explore the games we will build using SFML.
Now that we know about how we will be making these games, it is time to set up a development environment. This video will show us how to proceed with that.
If we don't know how the game is going to work on the screen, how can we possibly make it work in code? Let's learn how to plan the game and create a new project from the reusable project template.
Assets are things we need in order to make a game. It mainly includes font, sound and graphics. We must know how to add them. This video guides us with assets and understanding screen and internal co-ordinates.
It's time to apply all that we've learned and start coding the game. This video will guide us with the initial code and explain what each line of code does.
We've studied about SFML but using SFML can be a bit tricky. Let's explore how we can use SFML features to open a new window.
We need a way to stay in the program until the player wants to quit. Also, we must provide a way for the player to exit. Otherwise the game will go on forever. This video will help us achieve this goal.
At last, we need to add some real graphics in our game. Let's see how we will create and draw the game background and display it.
There will always be problems and errors in every project you make, that is guaranteed. Let's learn about the types of errors so that we are able to identify and rectify them whenever they occur.
Variables are the way that our C++ games store and manipulate values. If we want to know how much health the player has then we need a variable. Is the game over or still playing? That's also a variable. So, let's first learn about variables before we proceed with our game.
At this point, we know exactly what variables are, the main types, and how to declare and initialize them, but we still can't do many operations with them. We need to manipulate our variables, add them, take them away, multiply, divide, and test them. Let's explore manipulating variables.
In this video, we will add clouds, a tree and a bee to our game. This is going to be easy. We will use exactly the same procedure that we used in the previous section when we drew the background.
Random numbers are useful for a lot of reasons in games. Perhaps you could use them for determining what card the player is dealt with. This video will demonstrate using random numbers to determine the starting location and the speed of the bee and the clouds.
The C++ if and else keywords are what enable us to make decisions. We have already seen if in action in the previous section when we detected, in each frame, whether the player had pressed the Esc key. So, it'd be quite easy to learn.
Before we can move the bee and the clouds, we need to consider timing. As we already know, the main game loop executes over and over again, until the player presses the Esc key.
Let's use the elapsed time since the last frame, to breathe life into the bee and the clouds. This will solve the problem of having a consistent frame rate across different PCs.
As we progress with this game over the next three sections, the code will obviously get longer and longer. So, now it seems like a good time to think ahead and add a little bit more structure into our code. We will add this structure to give us the ability to pause and restart the game.
In the previous section, we briefly mentioned strings and we learned that a string can hold alphanumeric data. We didn't look at declaring, initializing, or manipulating strings. So let's do that now and briefly discuss the Text and Font classes.
Now we know enough about strings, SFML Text, and SFML Font to go about implementing the HUD. This video will show us how to add a score and a message to our game screen.
As time is a crucial mechanic in the game, it is necessary to keep the player aware of it. It will give him a sense of urgency as the end of the game draws near, and a sense of accomplishment if he performs well enough to maintain or increase his remaining time.
In programming, we often need to do the same thing more than once. The obvious example that we have seen so far is our game loop. There are a few different types of loop and we will look at the most commonly used.
If a variable is a box in which we can store a value of a specific type, like int, float, or char, then we can think of an array as a whole row of boxes. Let's learn about arrays in detail so we know how to use them.
We have already seen if, which allows us to make a decision whether to execute a block of code based upon the result of its expression. Sometimes a decision in C++ can be made better in other ways. This video will demonstrate using switch.
An enumeration is a list of all the possible values in a logical collection. They make the code clearer and less error-prone. Let's learn how to use class enumerations.
A function is a collection of variables, expressions, and control flow statements (loops and branches). In fact, any of the code we have learnt about in the course so far can be used in a function. Let's explore C++ functions in this video.
This last video of the section will guide us in using all the new C++ techniques to draw and move some branches on the tree.
As we now move closer to running the game. Let's add the code for the player's sprite, as well as a few more sprites and textures and then draw them.
Lots of different things depend on the movement of the player, such as when to show the axe, when to begin animating the log, and when to move all the branches down a place. This video shows us how to set up the keyboard handling for the player chopping.
Every game has to end badly, with either the player running out of time (which we have already handled) or getting squished by a branch. Let's see how to detect the player getting squished.
We've built the game but it has no sound yet. To complete the game, we will add three sounds. Each sound will be played on a particular game event. Let's identify what are the sounds and when we'll play them.
Now that we've built the game, let's take a look at these suggested enhancements for Timber!!! project. This video will show what the enhanced version of our game look like.
Understand and start with our Zombie Arena game.
Manage, change, or update easily to with OOP.
Player class benefits from knowing a few details about the overall environment the game is running in.
Controlling the Game Camera with SFML View
Start the game engine by using the updated code.
Manage the code to reduce its length and make it concise.
In this video, we will learn how to manage the code for game.
What do we do if we need to work on a number of complex objects which are needed in the main function? References are the solution to this problem.
SFML allows us to load a sprite sheet as a regular texture in exactly the same way we do for every texture. So, let's see how to do it.
Now that we have our hands on with C++ References and we are capable of creating Sprite sheets, let us step ahead and learn to generate a scrolling background.
By the end of this video you will be able to use and render the background. So, let's jump right in.
Pointers are variables that hold memory addresses. Typically, a pointer will hold the memory address of another variable. This sounds a bit like a reference but in this video, we will see how they are much more powerful.
Now that we have learned the basics about pointers. We will use a pointer to handle an ever-expanding horde of zombies.
The STL is a collection of data containers and ways to manipulate the data we put in those containers. Or to be more specific, it is a way to store and manipulate different types of C++ variables and classes. Let's learn more about STL in this video.
Thousands of zombies represent a new challenge. Not only would loading, storing, and manipulating thousands of copies of three different zombie textures take up a lot of memory, but also a lot of processing power too. This video will show us how to use the TextureHolder class to solve this problem.
We are now armed with the TextureHolder class to make sure that our zombie textures are easily available, as well as only loaded into the GPU once, we can look into building a whole horde of them.
Now we have a class to create a living, attacking, and killable zombie. This video will show us how to spawn a whole horde of them.
Since we have our TextureHolder class, we might as well be consistent and use it to load all our textures. Let's make some very small alterations to the existing code that loads textures for the background sprite sheet and the player.
As of now, we have a controllable character running around in an arena full of zombies that chase him. The problem is that they don't interact with each other. We need to detect collisions between the zombies and the player and give him bullets to defend himself.
Now that we've given the player bullets, we need to make them usable. This video will show us how to get the bullets working.
The player would see a mouse cursor on the screen, at this moment. We have to replace it with a crosshair which gives him an aim to shoot on and looks cool as well. Adding a crosshair is easy and only requires one new concept. We'll see that in this video.
In this video, we will code a Pickup class that has a Sprite, member as well as other member data and functions. We will add pickups to our game in just a few steps.
After all that hard work implementing the Pickup class, we can now go ahead and write code in the game engine to actually put some pickups into the game.
We need to know when certain objects from our game touch certain other objects. We can then respond to that event in an appropriate manner. In our classes, we have already added functions to call when our objects collide. So, let's see how we'll detect collisions.
Familiarize yourself with the details added to the code, especially the variable names.
Understand how to slow down our game loop.
HUD stays neatly positioned over the top of the main game action after drawing it.
Create and save the high score for each game.
Create sound effects to the game.
Enable the player to level-up.
Modify code and restart the game.
Play the sound and the final game.
To keep our game simple without losing the challenge, we will have the task of creating the need for two players to Play cooperatively. We also need to make sure the game is not too easy. This video shows us the basic features and the assets we need to create our game.
One of the problems that has been quite pronounced so far is how long and unwieldy the code gets. OOP allows us to break our projects up into logical and manageable chunks called classes. Let's see how we can make a big improvement to the manageability of the code.
As discussed earlier, we will code a class called Engine that will control and bind together the different parts of the Thomas Was Late game. This video guides you in building the Engine class, which will hold all other functions.
For instantiating the Engine class, we need a file that contains our main function and the code that instantiates the Engine class. Let’s see how we can do that.
We have seen how we can create objects from the classes of the SFML library. But, what if there is a class that has useful functionality, but is not quite what we want? This video will teach you how you can inherit from the other class.
Polymorphism allows us to write code that is less dependent on the types we are trying to manipulate. In this video, we'll take a look at what polymorphism means in its simplest form.
An abstract class is a class that cannot be instantiated and therefore cannot be made into an object. So, is it code that will never be used, then? Let's find out.
Now that we know the basics about inheritance, polymorphism, and pure virtual functions, we will put them to use. In this video, we'll build a PlayableCharacter class that has the vast majority of the functionality.
Now it's time for us to use inheritance for real. We will build a class for Thomas as well as Bob. They will both inherit from the PlayableCharacter class we have coded. Let's see how we do that.
In order to be able to run the game and see our new characters, we have to declare instances of them, call their spawn functions, update them in each frame, and draw them in each frame. Let's do that now.
There are different levels in a game. In this video, you will learn about the different levels in our game.
We need to add levels to the levelmanager class that we will create. This video will guide you through that.
For using the level manager class that we created earlier, we need to code for loading the level in the engine class.
After adding classes in engine, we will update the engine in order to make final changes in the view of our game in this video.
To detect if our players come in contact with other things in the game or each other, we need a collision detector.
Spatialization is making something relative to the space it is a part of. It gives the game a real-world feeling. In order to do that, we must first understand spatialization and how it works.
To manage all the sounds that will be used in our game, we will create a class and manage all our sound effects through that.
When a player nears a particular tile, a sound is emitted from the tile which makes it easy for the player to identify the type of tile they are going toward. This helps in creating a real-life effect in the game.
Now that we have all the functions for sound effects in the appropriate places, we will code for playing these sounds according to the time and place.
In order to interact with the player, we require text in our game. The HUD class helps in that.
To let the player know about his score, health, and even position, we need to know how to use the HUD class.
The Drawable class has just one function. It has no variables either. Furthermore, its one and only function is pure virtual. This means that if we inherit from Drawable, we must implement its one and only function. This video will guide you how we can solve this problem.
We will use the particle effect in our game. When a character Dies, he will explode in a starburst/firework-like particle effect. Let's see how we can achieve that.
Open Graphics Library is a programming library that handles 2D and 3D graphics. This video explores how OpenGL works.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.