A small Tetris implementation in C++ using Xlib for rendering.
- Game logic is separated from rendering:
game.h/game.cpp— board, pieces, rotations, collisions, line clearing, scoring, levels.render.h/render.cpp— drawing with Xlib (board, pieces, next piece preview, side panel).main.cpp— X11 initialization, main game loop, event handling.
- Supports:
- score;
- levels (fall speed increases with level);
- next piece preview;
- pause (button and
Pkey); - hard drop with
Space.
Keyboard:
Left/Right— move piece horizontally.Up— rotate piece.Down— soft drop (faster fall).Space— hard drop (instant fall).P— pause / resume.R— restart after game over.Esc— quit.
Buttons on the right panel:
- Pause / Resume — pause / continue the game.
- Exit — quit the game.
- C++17-compatible compiler or newer.
- X11 development headers:
- On Debian/Ubuntu:
sudo apt-get install libx11-dev
- On Debian/Ubuntu:
- CMake (the project is CMake-based).
git clone [https://github.com/vimcomes/tetris_x11.git](https://github.com/vimcomes/tetris_x11.git) cd tetris_x11 mkdir build cd build cmake .. cmake --build . ./tetris(The executable name may differ, check add_executable in CMakeLists.txt.)
CMakeLists.txt— CMake configuration.main.cpp— entry point, event loop, timing.game.h/game.cpp— game logic:Game::fieldboard state,- pieces and rotations,
- line clearing and scoring,
- level system and fall interval.
render.h/render.cpp— rendering:- board, grid, active piece,
- next piece preview,
- side panel with score, level and buttons.
- Rendering: double-buffered Xlib drawing to avoid flicker; palette allocated via
XAllocColor; ghost piece preview with toggle. - Gameplay: lock delay when touching the stack (including hard drop), 7-bag randomizer, tunable drop speed per level.
- UX: dashed ghost outline, options section with checkbox, line-clear flash effect, improved multi-line scoring.
- Scoring: bonuses scale with cleared lines (1/2/3/4 → 100/300/700/1200 * level).
Not explicitly specified yet. If you use this code in your own projects, please link back to this repository.