Skip to main content
← projects

Dec 23, 2024

Devris

Tetris clone in C++ with SDL2

C++SDL2Game Dev

Objective

Build a Tetris clone in C++ using SDL2, with the full game loop, piece rotation, collision detection, line clearing and scoring written from scratch.

Tools & Technologies

SDL2

Share This

Details

Devris is my Tetris clone, written in C++ with SDL2 for rendering and input. I wanted to build a real game loop for once: fixed timestep updates, frame-rate independent rendering and proper keyboard handling, instead of just a scripted demo.

The game covers everything you'd expect: a 10×20 grid, all seven tetrominoes with their rotation states, wall kicks, soft and hard drops, and line clearing with scoring and level progression. Pieces spawn using the standard bag randomizer, so you never get flooded with the same piece over and over.

The rotation system turned out to be the hardest part by far. Naively rotating a piece around its bounding box gives wrong results for most tetrominoes, so real Tetris uses the Super Rotation System (SRS) with offset tables for every piece and rotation state. Getting the wall kicks right (where a piece shifts sideways when you rotate it against a wall) took the most iterations of anything in this project.

While making this project I learned how a real game loop works, how SDL2 handles rendering and input, and that even a "simple" game like Tetris has way more going on under the hood than you'd think.

Source Code


Take a closer look at the source code here: GitHub

Gallery

Devris gameplay

Devris gameplay