Tetris

TypeScriptCollision detectionPiece rotationLine clearing

Rotate and stack tetrominoes on a tile board, clear full rows, and keep the stack below the spawn area. The implementation keeps board state, shape matrices, collision checks, row clearing, and restart behavior small enough to read as one complete game loop.

Built in TypeScript. Explore more projects on Projects

How it works

A tile-board Tetris implementation with local shape matrices, collision checks, rotation, line clearing, and restart-on-game-over behavior.

Implementation notes

The board uses 12 columns and a shared tile size, with occupied cells stored in a lightweight matrix.

Each spawned tetromino is selected from local shape definitions with precomputed rotation states.

Movement and rotation are blocked when the next position would hit a wall, the floor, or a locked cell.

When a piece lands, its blocks become board cells, completed rows are removed, and a new piece spawns.

Controls

MoveArrowLeft / ArrowRightA / D
RotateArrowUpW
Faster dropArrowDownS