Why do I use C and C++ for writing games?
I am currently working on a sort of tactical strategy TD named Cats vs. Flowers. To develop it, I use a combination of C++ and Raylib. So, why did I choose those?
In the past, I have made some games in Godot. Over the time I spent using it, I realized that I preferred working on a lower level (for example by using VisualServer for rendering), so I realized that maybe it isn't for me. I don't like using game engines in general. I think that for what I make (simple 2D games), they are overkill and a lot of the time spent with them is devoted to working around the implementations of features like collisions, sprites etc. whereas with a simple graphics library I can quickly and more intuitively implement the same things, while gaining a deeper understanding of what is going on.
Engines also tend to produce quite big binaries while I never touch many of the included features. Godot can be recompiled to strip unwanted components, but that would still leave me with a GUI-based editor, while I prefer working within code and text files.
Due to these issues, I began to look for other options. My first choice was MonoGame, since I was using C# at the time. However, I did not like the dependency on the MGCB editor. So I did not settle on it.
Sometime later, I have started learning C. One of my first projects in this language was a falling-sand simulator, for which I decided to use Raylib because of its neat balance between control and abstraction.
I like C as an option for game development, because it provides high performance (no JIT, GC or interpreter), has direct support for many popular game development libraries (GLFW, Box2D, ENet etc.), runs on basically everything and forces you to plan your code and what data structures you will use, making it fun in its own way and encouraging active thinking compared to more high-level options. I like knowing exactly what my code is doing.
To develop Cats vs. Flowers, I decided to use the same toolset as for the previously mentioned simulator in order to minimize any possible friction. However, as the game grew larger, I moved the codebase to C++ to speed up adding new content and make the code somewhat more readable. That is where I am now and probably will be in the foreseeable future. However, C is still my default option for new projects :)
What else could I use?
Let's explore some other choices for programming languages outside of C/C++, because there are quite a few:
- Odin - I have considered picking it up, because it is actually a good choice. It pre-packages SDL and Raylib with a source translation from C to Odin (so no bindings required!), along with other utility libraries for things like compression, networking, Unicode etc. Apparently it also can export to WebAssembly. I will take a look at it sometime.
- Rust - The most popular choice when using Rust, Bevy is modular and well-maintained, but still expects you to use their ECS if you interact with it. Macroquad is also being developed, but the commit history is quite sparse, which doesn't really inspire confidence. There are also bindings for SDL3 and Raylib, but I don't see any advantage compared to using them directly.
- Scratch - We have gone full circle.