Tetris (raylib classic)¶
Grid logic, rotation, line clears, score HUD.
▶ Run in browserUpstream: https://github.com/raysan5/raylib-games/tree/master/classics/src
Licence: this port's own code is offered under Zlib, not the SimVX Examples Licence the rest of the gallery carries. See ATTRIBUTION.md for the upstream it re-implements, the terms of anything it bundles, and the credit each one requires.
Ports live in the repository only, not in the simvx-examples distribution, because each is a derivative work licensed individually against the game it re-implements. Read it with git clone https://git.simvx.com/simvx/simvx.
Tags: port tier-0
Tetris (raylib classic): SimVX port¶
A source-faithful port of tetris.c from
raylib-games/classics
by Marc Palau and Ramon Santamaria. The gameplay is a direct translation of the C
original: a sentinel-bordered 12x21 grid, the empty/moving/full/block/fading cell
states, gravity with a held soft drop, lateral auto-repeat, a rotation lockout, and
the line-clear flash.
Everything is drawn procedurally, so the port bundles no upstream art, audio, or
fonts. See ATTRIBUTION.md and UPSTREAM_LICENSE.md.
What it shows¶
Immediate-mode 2D drawing: the whole playfield, preview and HUD come out of one
on_drawon adynamicnode, with no sprites or scene nodes per cell.Typed input actions shared by keyboard and touch, so the same game logic serves desktop and the web export.
Resize-aware layout: the cell size, the panel origin and every text scale are recomputed from
tree.screen_sizeeach frame.A menu / play / game-over state flow inside a single node.
Run¶
# from the repo root
uv run python examples/ports/raylib_tetris/main.py
Controls¶
Action |
Keyboard |
Touch |
|---|---|---|
Move sideways |
LEFT / RIGHT or A / D |
Tap left or right half of the board |
Rotate 90° CW |
UP or W |
Tap above the board |
Soft drop |
DOWN or S (after a brief hold) |
Tap below the board |
Pause / resume |
P |
Tap the side panel (any tap resumes) |
Start / restart |
SPACE or ENTER |
Tap anywhere |
Quit |
ESC |
- |
Web export¶
uv run simvx export web examples/ports/raylib_tetris/main.py \
-o /tmp/raylib_tetris.html
Source files¶
File |
Summary |
Lines |
|---|---|---|
Tetris (raylib classic): Grid logic, rotation, line clears, score HUD. |
59 |
|
0 |
||
0 |
||
Tetris: gameplay node. |
558 |
Source¶
1#!/usr/bin/env python3
2# /// script
3# requires-python = ">=3.14"
4# dependencies = ["simvx-core", "simvx-graphics"]
5# ///
6"""Tetris (raylib classic): Grid logic, rotation, line clears, score HUD.
7
8# /// simvx
9# tags = ["port", "tier-0"]
10# upstream = "https://github.com/raysan5/raylib-games/tree/master/classics/src"
11# web = { width = 600, height = 600, responsive = true }
12# ///
13
14A source-faithful translation of raylib's classic ``tetris.c`` into a single
15SimVX ``Node2D``. The gameplay follows the C original: a sentinel-bordered
1612x21 grid, the empty/moving/full/block/fading cell states, gravity with a
17held soft drop, lateral auto-repeat, a rotation lockout, and the line-clear
18flash. Around that the port shows immediate-mode 2D drawing (``on_draw`` on a
19``dynamic`` node), typed input actions dispatched from both keyboard and touch
20zones, a menu / play / game-over flow, and resize-aware text layout that fits
21itself to the window.
22
23Controls: LEFT/RIGHT or A/D move, UP or W rotates, DOWN or S soft-drops after
24a brief hold, P pauses, SPACE or ENTER starts and restarts, ESC quits. By
25touch, tap the left or right half of the board to move, above it to rotate,
26below it to soft-drop, and on the side panel to its right to pause.
27
28Run::
29
30 uv run python examples/ports/raylib_tetris/main.py
31
32Web export::
33
34 uv run simvx export web examples/ports/raylib_tetris/main.py -o /tmp/raylib_tetris.html
35
36Attribution and upstream licence: see ``ATTRIBUTION.md`` and
37``UPSTREAM_LICENSE.md`` beside this file.
38"""
39
40import os
41import sys
42
43_HERE = os.path.abspath(os.path.dirname(__file__))
44if _HERE not in sys.path:
45 sys.path.insert(0, _HERE)
46
47from nodes.tetris_game import TetrisGame
48
49from simvx.graphics import App
50
51WIDTH, HEIGHT = 600, 600
52
53
54def main():
55 App(title="Tetris (raylib classic)", width=WIDTH, height=HEIGHT).run(TetrisGame())
56
57
58if __name__ == "__main__":
59 main()