Tetris on the SugarCraft stack
SugarCraft runtime, CandySprinkles for rounded borders + per-piece colours, deterministic 7-bag RNG, ghost piece, hard drop, hold, level-driven gravity ramp, NES-classic line-clear scoring. Full SRS wall-kicks via official Tetris Association tables, T-Spin detection via the 3-corner rule, Back-to-Back (1.5ร) and combo bonuses, DAS/ARR keyboard timing (167/50 ms), and perfect-clear detection (+5000/level).
composer require sugarcraft/candy-tetris
composer install
./bin/tetris
# Controls
# โ / โ Move left / right
# โ / x Rotate clockwise
# z Rotate counter-cw
# โ Soft drop
# Space Hard drop
# p Pause / resume
# q Quit
| Class | Method | Description |
|---|---|---|
| Tetromino | new(type) | Create a tetromino piece |
| Piece | rotate(direction) | Rotate piece |
| Piece | rotationsWithKicks(delta) | All valid rotated positions (naive + SRS wall-kick offsets) |
| Piece | move(dx, dy) | Move piece |
| Board | new(width, height) | Create game board |
| Board | lock(piece) | Lock piece into board |
| Board | clearLines() | Clear completed lines |
| Board | isPerfectClear() | True iff every cell is null (empty board after a perfect clear) |
| Bag | next() | Get next piece from bag |
| Score | add(lines, level) | Add score for lines cleared |
| Game | tick() | Process game tick |
| Game | state() | Get current game state |
| SrsKickTable | kicks(piece, from, to) | Return kick offsets for a rotation transition |
| SrsKickTable | allKicks(piece) | Return all four transition tables for a piece |
| Scoring\TSpin | detect(board, piece, wasRotated) | Detect T-Spin state using the 3-corner rule; returns TSpin(active, mini) |
| Scoring\TSpin | T_SPIN_POINTS / T_SPIN_MINI_POINTS | Base score constants (400 / 100, scaled by level+1) |
| Input\Das | create(dasMicroseconds, arrMicroseconds) | Factory โ defaults 167_000 / 50_000 ยตs |
| Input\Das | advance(us) | Accumulate microseconds; returns fresh Das |
| Input\Das | leftFiring() / rightFiring() / downFiring() | Whether the direction should fire at current tick |
VHS-recorded GIFs of every example shipped with the app. Regenerated automatically on every push that touches the source.