A browser Tetris game powered by Rust and WebAssembly. Play immediately on GitHub Pages.
The game adapts to desktop and mobile screens, supports keyboard and touch controls, and includes solo challenges, an AI battle, and deterministic replay codes.
The game currently offers four challenge goals through the in-game GAME MODE selector (described below as objective cards). The mode panel shows the relevant timer or line progress; VS AI Battle also displays the rival board and match statistics.
| Mode | Goal |
|---|---|
| Marathon | Keep playing and improve your score until the board tops out. |
| 40 Lines Sprint | Clear 40 lines as quickly as possible. |
| Ultra 2-Min | Clear as many lines as possible within two minutes. |
| VS AI Battle | Trade garbage attacks with an AI opponent. Choose Easy, Normal, Hard, or Grandmaster difficulty. |
- Seven tetrominoes with a 7-bag randomizer, ghost piece, hold slot, SRS wall kicks, lock delay, and line-clear scoring.
- Line-clear scoring supports combos, back-to-back (B2B), perfect clears, and garbage attacks; VS AI Battle displays PPS and APM statistics.
- Rebindable keyboard controls, touch controls, and adjustable DAS / ARR / SDF handling settings.
- Replay export and import using compact deterministic codes, with playback from 0.5× to 4× speed.
- Synthesized sound effects and a high score stored in the browser's
localStorage. - Responsive layout for landscape and portrait screens.
| Action | Default keys |
|---|---|
| Move left / right | A / D or ← / → |
| Soft drop | S or ↓ |
| Rotate clockwise | W, K, or ↑ |
| Hard drop | Space or J |
| Hold piece | C or Shift |
| Pause / resume | P or Esc |
Open the gear button (⚙) to change key bindings. On mobile, use the on-screen controls. The ⚡ panel adjusts DAS, ARR, and SDF.
Prerequisites: Rust stable, the wasm32-unknown-unknown target, wasm-pack, Node.js 20 or newer, and npm.
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
npm ci
wasm-pack build --target web
npm run devOpen the local address printed by Vite (by default, http://localhost:1421/).
cargo test
cargo clippy --all-targets
npm test
wasm-pack build --target web
npm run build
npm run previewVite writes the production site to dist/. GitHub Actions runs the Rust test-count gate (at least 60 tests), Rust tests, Clippy, the WebAssembly build, Vitest, and the Vite production build for pull requests and pushes to main. A push to main also deploys dist/ to GitHub Pages.
To enable deployment, set Settings → Pages → Build and deployment → Source to GitHub Actions. The workflow publishes to https://zhyzx35607.github.io/Tetris/.
MIT