Mousetrap

a sokoban-style puzzle game in c++ and sdl3, no engine, with hot reloading and levels inside levels.

mousetrap is a sokoban-style puzzle game i made in six weeks for my c++ course at yrgo in sweden. you play a mouse who pushes and pulls blocks, eats all the cheese in the level and then makes it to the purple portal. it's written in c++20 for windows and built with cmake, ninja and clang++. there's no game engine underneath it: sdl3 handles the window, input and drawing, and mostly everything else is written for this game, apart from the material my teacher gave us.

the logic lives in a dll that a small host program loads, and when i rebuild the dll the host swaps it in while the game keeps running, so code changes show up without a restart. f9 saves the whole game state and f10 restores it, which made it really easy to playtest. all the memory is allocated up front as one 10 mb block and split into arenas for images, levels, entities, undo commands, input, ui and audio. the base for that, the hot reloading, the undo and the input buffer came from my teacher's course material, and the game on top of it, the levels, the rules and the tunnels, is what i built.

i drew the levels in tiled and exported them as json, which the game reads with nlohmann/json. each level has a tile layer and an entities layer for the player, the blocks and things like cheese, and the tileset marks which tiles are walkable. the menu works with only the keyboard or only the mouse, and neither needs the other. menus like that matter a lot to me and they're also very fun to make.

the tunnels were the hardest part. a mouse hole leads into a level nested inside another level, in chains of up to three, and the undo history, moving between levels and checking whether a level is complete all have to work across the whole chain. they're also what i'm proudest of. making mousetrap taught me about managing memory, structuring a bigger c++ project and using tools like cmake, tiled and hot reloading.

sound is played through fmod. the music and sound effects were made by ai, generated with python scripts (numpy) instead of recorded or downloaded. i had always wanted to try exactly that, and it sounds pretty alright i guess. the text is set in press start 2p, and the pictures on the assets tab are the title screen, the tileset and every level, including the tunnels inside them, drawn from the real level files, since the game has no screenshot button.

stack: c++20, sdl3 with sdl3_image and sdl3_ttf, fmod, dear imgui, nlohmann/json, tiled, cmake, ninja and clang++, plus python with numpy for the audio.

click anywhere or press esc to close