3D Voxel Game in C

Destructible voxel terrain, flying enemies, and a renderer derived on Post-it notes.

Screenshot from a 3D platform game written in C.

2026 update: I haven’t used Windows for a long time, but I’d been wanting to play this game again, and the original binary was compiled only for Windows. I’d never got around to migrating it to SDL2, but an AI agent finally let me just one-shot the migration. So the game I built nine years ago is playable again at platform-game.schmelczer.dev1.

I titled my first proper university project Platform Game. I’ve clearly come a long way since then, yet one thing hasn’t changed: I’m still bad at naming things.

Back in 2017, I created an actually fun 3D game in pure C with the help of SDL 1.22. I’d wanted to build it ever since I first downloaded GameMaker3 and realised that I could make a video game. I’d already tried with Avoid4, and Platform Game is essentially an upgraded 3D version of it.

The maps are randomly generated, but the platforms are laid out so that every jump remains possible with the player’s gravity and jump-strength settings. The world is also fully destructible, voxel by voxel. You can build structures to hide from flying enemies, although once they merge and grow large enough, they can destroy the terrain too. After collecting enough power-ups, you can shoot back or sacrifice points to slow down time.

One feature I distinctly recall is the save file format. Initially, the game dumped the entire procedurally generated map into a file, so one saved map could reach hundreds of megabytes. I realised that each map had long runs of similar voxels, mainly air at the top and ground at the bottom. Encoding those runs as repetitions massively reduced the file size. I ended up discovering run-length encoding5, although I later learnt I wasn’t the first person to do so.

One thing I didn’t discover during this project was how to do computer graphics properly: I settled on a software renderer capable only of drawing cubes after deriving a cube’s 3D-to-2D projection using trigonometry and a lot of Post-it notes. Doing it properly had to wait a few more years for a 2D ray tracer6.

I’ve made the source code public, more as a reminder to myself than as something others should learn from. The project is neither elegant nor efficient, but it produced a genuinely fun game and it made me fully realise my passion for creating virtual worlds.

  1. https://platform-game.schmelczer.dev/↩
  2. SDL 1.2: https://www.libsdl.org/↩
  3. GameMaker: https://gamemaker.io/↩
  4. Avoid: https://schmelczer.dev/articles/avoid-early-web-game/↩
  5. run-length encoding: https://hydrolix.io/blog/run-length-encoding↩
  6. a 2D ray tracer: https://schmelczer.dev/articles/sdf-2d-ray-tracing/↩

Searches titles, descriptions, and the full text of every article.

    ↑↓ to move ↵ to open Esc to close