There are different levels in a game. In this video, learn about the different levels in your game.
- [Instructor] Welcome to the third section of this course Building Playable Levels and Collision Detection. We'll start this section by designing levels in a text file. We would then build a levelManager Class that will load levels from a text file, convert them into data our game can use, and keep track of the level details such as spawn position, current level, and allowed time limit. Then, we'll update the game engine to use levelManager. And lastly, we'll code a polymorphic function to handle the collision detection for both Bob and Thomas.
Now we start with the first video of this section Designing Some Levels. In this video, we are going to take a look at the code and images for level designs. Remember our Sprite sheet that we introduced in section one abstraction and code management? Here it is again. Annotated with numbers that represent each tile that we will build our levels from. I placed the screenshot on a gray background so you could see clearly the different details of the Sprite sheet. The checkered background represents the level of transparency, so all of the tiles except for number one will reveal at least a little of the background behind them.
Tile zero is completely transparent and will be used to fill in the gaps where there aren't any other tiles. Tile one is for the platforms that Thomas and Bob will walk on. Tile two is for fire tiles, and tile three is for water tiles. Tile four, you might need to look quite closely to see. It has a white square outline. This is the goal of the level where Thomas and Bob must get to together. Keep this image in mind as we discuss designing the levels. We will enter combinations of these tile numbers into text files to design the layouts.
Here's an example that will help. This code translates to the level layout shown here. Note that to get the view shown, I had to zoom out the view, also the image is cropped. The actual start of the level would look like this. The first point of showing you these images is twofold. Firstly, you can see how you can quickly construct level designs using a simple and free text editor. Secondly, it demonstrates the game play aspects of the design. From left to right in the level, Thomas and Bob first need to jump a small hole, or they'll fall to their deaths.
Then, they have a large expanse of fire to traverse. It is actually impossible for Bob to jump that many tiles. The players will need to work together for the solution. The only way that Bob will clear fire tiles is by standing on Thomas' head and jumping from there. As you can see here, it is then quite simple to get to the goal and move on to the next level. I strongly encourage you to complete this section, and then spend some time designing your own levels. I've included a few level designs to get you started.
They are in the levels folder that we added to the project back in section one abstraction and code management. You can see them here. Let's see some zoomed out views of the game along with the code of the level design. The code is probably more useful than reproducing the actual textual content. If you do want to see the code, just open up the files in the levels folder. This is the levels folder. This is what the code looks like. See this is level layout that the previous code will produce.
Look at this image. This level is the leap of faith, level I, referred to in section one. I have highlighted the platforms as they are not very clear in the zoomed out image. The provided designs are simple. The game engine will be able to handle very large designs however. You have the freedom to use your imagination and build some really big and hard to complete levels. Of course, these designs won't actually do anything until we learn to load them and convert the text into a playable level.
Additionally, it won't be possible to stand on any platforms until we have implemented collision detection. We'll move to loading the level designs. In this video, we have designed levels. Great! In the next video, we'll take a look at building the levelManager Class.
This course was created and produced by Packt Publishing. We are honored to host this training in our library.
- Abstract classes
- Level design
- Collision detection
- The HUD class
- Extending SFML classes
- Particle systems