rustris-0.4.0 is not a library.
Rustris
A guideline-compliant terminal Tetris written in Rust, with LAN multiplayer support.
Install
Or build from source:
Requires Rust 2024 edition (1.85+). On Linux,
libasound2-dev(or equivalent) is needed for audio support.
Game Modes
| Mode | Objective |
|---|---|
| Marathon | Clear a target number of lines (default 150) |
| Sprint | Clear lines (default 40) as fast as possible |
| Ultra | Score as high as possible within a time limit (default 120s) |
| Endless | Play with no goal until game over |
| Versus | LAN 1v1 - send garbage lines to your opponent |
Versus Mode (LAN Multiplayer)
Play 1v1 over a local network. One player hosts, the other joins.
Quick Start
Terminal 1 (Host):
Terminal 2 (Client):
Replace 127.0.0.1 with the host's LAN IP for cross-machine play.
You can also start Versus from the in-game menu by cycling to the Versus mode and selecting Host or Join.
Garbage System
Clearing lines sends garbage to your opponent:
| Clear Type | Attack |
|---|---|
| Single | 0 |
| Double | 1 |
| Triple | 2 |
| Tetris | 4 |
| T-Spin Single | 2 |
| T-Spin Double | 4 |
| T-Spin Triple | 6 |
| T-Spin Mini Single | 0 |
| T-Spin Mini Double | 1 |
| Back-to-Back | +1 |
| Perfect Clear | 10 |
Combo bonus (added on top): 0-1 combo = +0, 2-3 = +1, 4-5 = +2, 6-7 = +3, 8-10 = +4, 11+ = +5.
Pending garbage is absorbed when you clear lines (cancel before send). Uncleared garbage is applied to your board on lock.
Versus Rules
- Level is fixed (no level-up during a match)
- Pause is not allowed; Esc opens a Continue/Forfeit menu
- No records are saved for Versus games
Controls
| Key | Action |
|---|---|
| Left / Right | Move piece |
| Down | Soft drop (+1 per cell) |
| Space | Hard drop (+2 per cell) |
| Up / X | Rotate clockwise |
| Z | Rotate counter-clockwise |
| C | Hold piece |
| Esc / P | Pause (Forfeit in Versus) |
Features
- Super Rotation System (SRS) with full wall kick tables (toggleable)
- 7-bag randomizer (or pure random)
- Hold piece (toggleable)
- Next queue preview (0-6 pieces, configurable)
- Ghost piece (toggleable)
- Lock delay (0-2s, configurable) with move/rotate reset (0-30 or unlimited)
- DAS/ARR input handling
- Line clear animation (toggleable)
- Guideline scoring - T-Spin (Mini/Full), Back-to-Back, Combo, All Clear
- Guideline gravity with level cap setting
- BGM & SFX with polyphonic playback
- Leaderboard - top 10 per mode, recorded only under default settings
- LAN Versus - P2P TCP multiplayer with garbage system, dual-board rendering, rematch support
Settings
| Setting | Modes | Range | Default | Description |
|---|---|---|---|---|
| Level | Marathon, Endless, Versus | 1-20 | 1 | Starting level |
| Goal | Marathon | 10-300 (step 10) | 150 | Lines to clear |
| Goal | Sprint | 10-100 (step 10) | 40 | Lines to clear |
| Time | Ultra | 30-300s (step 10) | 120s | Time limit |
| Cap | Marathon, Endless | 1-20 / INF | 15 | Maximum level |
| Next | All | 0-6 | 6 | Next queue preview count |
| Lock | All | 0.0-2.0s (step 0.1) | 0.5s | Lock delay before piece locks |
| Reset | All | 0-30 / INF | 15 | Move reset limit during lock delay |
| Ghost | All | ON / OFF | ON | Ghost piece visibility |
| Anim | All | ON / OFF | ON | Line clear animation |
| Bag | All | ON / OFF | ON | 7-bag randomizer (OFF = pure random) |
| SRS | All | ON / OFF | ON | Super Rotation System with wall kicks |
| Hold | All | ON / OFF | ON | Hold piece |
| BGM | All | ON / OFF | ON | Background music |
| SFX | All | ON / OFF | ON | Sound effects |
Project Structure
src/
main.rs Entry point, CLI args (--host/--join), terminal init/cleanup
ui/
menus.rs Mode select, settings, records screens
menus_versus.rs Versus Host/Join sub-menus with port/address input
game_loop.rs Single-player game loop, DAS input, SFX dispatch
versus.rs Versus game loop, lobby, countdown, garbage, rematch
game/
types.rs GameMode, LastMove, ClearAction, timing constants
mod.rs Game struct and all gameplay logic
garbage.rs Attack calculation, garbage queue, cancel logic
net/
protocol.rs NetMessage enum, GarbageAttack, BoardSnapshot types
transport.rs Connection: frame encoding/decoding, non-blocking TCP I/O
host.rs TCP listener (non-blocking accept)
client.rs TCP connect
mod.rs Network module exports
render/
board.rs Single-player board rendering
versus.rs Dual-board rendering, lobby/countdown/result screens
menus.rs Menu/overlay rendering (pause, game over, settings, etc.)
mod.rs Shared render utilities, title, piece preview
piece.rs Piece/Bag structs, SRS data (rotation states, kick tables)
records.rs Leaderboard persistence (JSON via serde)
audio.rs BGM and SFX playback
settings.rs Settings and VersusSettings structs
bgm_score.rs BGM note/melody data
Dependencies
- crossterm - Terminal manipulation
- rand - Bag shuffling and random generation
- rodio - Audio playback
- serde / serde_json - Record and network message serialization
- dirs - Platform data directory resolution