← udacity portfolio
cpp nd · systems cpp · December 2019

Snake (SDL2 game)

Capstone of the C++ nanodegree foundations module — the classic Snake game in SDL2 + modern C++ with score persistence.

What it did

Build the classic Snake game in SDL2 + modern C++. Fixed-timestep game loop, keyboard input, collision detection on a grid, score persistence to a text file, scaling difficulty.

The C++ nanodegree’s foundations capstone is meant to demonstrate the RAII + smart-pointer + STL patterns from the first half of the course — Snake fits well because the SDL handles need cleanup on exit and the data structures (deque for snake body, point for food) come straight from <deque> and <utility>.

What was actually tricky

What I’d do differently with hindsight

What it taught me

Real-time loops have a different feeling than batch programs. The game loop’s tight constraint (16 ms budget at 60 fps, regardless of state) trains a different kind of discipline. Every later real-time-ish project (the EKF in the simulator, the perception pipeline) inherited the same intuition: the loop has a budget; spend it carefully.


Source archive: Shivam-Bhardwaj/snake-game (archived)
Writeup last touched: 2026-05-22