Dodge the Creeps 2D
A recreation of the classic Godot Tutorial game but with custom implemented UIs and collisions, based on SDL3 and pure C.
Published onUpdated on
1.485
Description
This project serves as a convenient way for me to get into low level programming with C, as a challenge to recreate a simple 2D engine under SDL3.
Installation
Requirements:
- SDL3: The main library component. This abstracts over the main operating system’s windowing and graphics system. This also provides a simple way to have a 2D rendering pipeline.
- SDL3_Image: The sister library of SDL3 that allows loading other images
apart from just bitmap files (
.bmp). - SDL3_TTF: The sister library of SDL3 that allows loading arbitrary TTF font files instead of using the extremely limited debug set of characters.
- CMake: Cross-platform C/C++ build tool.
You can choose to whether install these libraries by vendoring in and configuring CMake to include the local libraries, or have them as system libraries and let CMake find them from your system (I’m using Homebrew with system libraries).
Then, run the CMake file into a build folder, then Make for your corresponding
system. The binary should be configured correctly in the build folder. All
commands must be run on the project root directory, since asset paths are ./assets/....
Documentation
I tried to comment as many functions as there are in header files. But here’s the rundown of how this application does:
- A renderer and a window with SDL are created on initialization.
- A main struct
AppStateholds all information about the game: the current state (starting, running or over), the score, the player and the enemies. - Player is loaded with their sprites, these are loaded at all time.
- Enemies are loaded independently, but have pointers pointing to shared sprites.
- Collisions are checked simply with a simple axis-aligned bounding box struct
BoundingBox. - After everything, clean up and free memory.
This is my first project using the C language (other projects use a subset of C++, so it doesn’t count). There will be glaring flaws and bad memory handling.