The implementation part was quite easy, but some parts of the game did have some what-why-and-omg parts. However, I must still admit that I did some dirty copying from my previous version of the game and therefore quite many parts of the game are written in the so called “clean” and sophisticated C++. Let’s see if I can manage to cover the highlights from this project in this post. Let the adventure begin!
At the beginning…
Graphics were easy to implement in the HTML5 version of the game by using the Canvas 2D API. However, this API is not available in C++ and therefore I needed to pick at least some library for creating the application window and for drawing the graphics. Here I decided to dive into the world of SDL2 and SDL2_ttf. SDL2 is a commonly used framework for building media applications (like games) and SDL2_ttf is an TrueType font rendering extension library for SDL2.
When I started this project, I also wanted to try using an automatic system to construct the building environment. I decided to refresh my memory about how to use the CMake utility, which is a build construction system that I previously used couple years ago.
Configuring the build process was quite time consuming even though the actual CMake modules were not that hard to implement. It was interesting to note that I’ve almost forgotten everything that I have previously learned about CMake. CMake uses a… let’s say… quite interesting syntax to configure the build process. Luckily it is a quite widely used tool, so it was a somewhat easy to find good examples and documentation about how to use it.
I managed to write the main CMakeLists in the project root. It uses two hand written custom modules from the cmake folder to find SDL2 and SDL2_ttf libraries and headers. These custom modules are highly fragile as they currently support only finding the libraries via environment variable definitions while also requiring the CMake to be executed in a Windows environment.
All three scenes (welcome, court and end-game) inherit the pure abstract Scene class, which requires scenes to implement all scene/state specific functions. This made scene changing easier as each scene must satisfy and provide implementations that are required from the scene definition.
Thanks for reading!
Gameplay video in YouTube: https://www.youtube.com/watch?v=lXs4EDC0KEE
Game source code in Github: https://github.com/toivjon/sdl2-pong