Skip to main content
← projects

Dec 23, 2024

Devris

Tetris clone in C++ with SDL2

C++SDL2Game Dev

Objective

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

Tools & Technologies

SDL2

Share This

Details

Devris is a Tetris implementation written in C++ using SDL2 for rendering and input. The goal was to build something with a real game loop (fixed timestep updates, frame-rate-independent rendering, keyboard input handling) rather than just a scripted demo.

The core engine covers everything the game needs: a 10×20 grid represented as a 2D array, the seven standard tetrominoes with their rotation states, wall-kick collision resolution, soft and hard drop, and line-clear scoring with level progression. Piece spawning uses the standard bag randomizer so the same piece never appears more than twice in close succession.

One of the more interesting implementation details is the rotation system. Naively rotating a piece around its bounding box produces wrong results for most tetrominoes. Tetris uses a Super Rotation System (SRS) with defined offset tables per piece per rotation state. Getting wall kicks right (the piece shifting horizontally or vertically when rotating near a wall or existing blocks) took the most iteration.

SDL2 handles the window, renderer, and keyboard events. All game state is rendered each frame by iterating the grid and drawing colored rectangles. No sprite sheets, keeping the rendering path minimal.

Source Code


Source available on GitHub.

Gallery

Devris gameplay

Devris gameplay