My second project in C++ from scratch was skydive. In this game, the goal is to collect as many coins (yellow square) as possible while avoiding enemies (red rectangle). The game gets faster and faster so that the game becomes more and more difficult in the long run.
The goal at this point was to practice object-oriented programming more.
Button | Movement | |
---|---|---|
A | Move left | |
D | Move right |
This UML chart visualizes the dependencies of the individual classes and structures.
It was important to me that there is an area at the beginning of the game that allows game designers, for example, to make settings. That's why I added a so-called setup zone with comments at the beginning (Figure 2).
Part of the object-oriented programming was to outsource the input handler to its class. This allowed me to access the input handler in the game manager at any time.
I use the same principle for the player's health bar. Here the first setting from the setup zone is used because the length of the array is configured over it. This means that if four lives are entered in the setup zone, this is also the length of the array for initialization (Figure 4).
To be able to play the game on all computers at the same speed, it is necessary to pass the delta time into the update function. This is necessary so that the delta time can be multiplied by the movement speed.
To get the delta time, the time is measured at the beginning and the end of each frame and the difference is calculated. If the result is greater than half a second, the value is set to 0.5 (Figure 5).
Once the value has been passed to the update function by the game manager, the value can be passed to the individual classes, such as the input handler (Figure 6).
Link to the repository: https://christian-brueckl.de:8443/svn/Skydive/
_________________________
Username: showcase
Password: showcase