Tetris (raylib classic)

Grid logic, rotation, line clears, score HUD.

▶ Run in browser

Upstream: 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_draw on a dynamic node, with no sprites or scene nodes per cell.

  • One typed action for sideways movement, fed by the arrow keys, A/D, a controller’s D-pad and its left stick alike, so the game logic never asks which device the player is using.

  • A TouchController in the dpad_and_buttons layout: it publishes itself as a real controller, so the game’s Controller bindings play it with no extra wiring, and it leaves the screen once a real controller is used.

  • Resize-aware layout: the cell size, the panel origin and every text scale are recomputed from viewport_size each frame.

  • A menu / play / game-over state flow inside a single node.

Run

# the export runs in a copy made by `simvx examples copy ports_raylib_tetris`
simvx examples run ports_raylib_tetris

Controls

Action

Keyboard

Controller / on-screen pad

Move sideways

LEFT / RIGHT or A / D

D-pad left / right, or the left stick

Rotate 90° CW

UP or W

A, or D-pad up

Soft drop

DOWN or S (after a brief hold)

B, or D-pad down

Pause / resume

P

Start (a tap anywhere also resumes)

Start / restart

SPACE or ENTER

A or Start (a tap anywhere also works)

Quit

ESC

Back

Web export

simvx export web main.py \
    -o raylib_tetris.html

Source files

File

Summary

Lines

main.py

Tetris (raylib classic): Grid logic, rotation, line clears, score HUD.

53

__init__.py

0

nodes/__init__.py

0

nodes/tetris_game.py

Tetris: gameplay node.

519

Source

 1#!/usr/bin/env python3
 2# /// script
 3# requires-python = ">=3.14"
 4# dependencies = ["simvx-core", "simvx-graphics"]
 5# ///
 6
 7# /// simvx
 8# tags = ["port", "tier-0"]
 9# upstream = "https://github.com/raysan5/raylib-games/tree/master/classics/src"
10# web = { width = 600, height = 600, responsive = true }
11# ///
12"""Tetris (raylib classic): Grid logic, rotation, line clears, score HUD.
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), one typed action serving the keyboard, a controller and the
20on-screen pad at once, a menu / play / game-over flow, and layout that follows
21the 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. On a
25controller, or on the D-pad this draws on the glass for a touchscreen, the
26D-pad moves and soft-drops, A rotates, B soft-drops and Start pauses; a tap
27anywhere starts a game and resumes a paused one.
28
29Run::
30
31    simvx examples run ports_raylib_tetris
32
33Web export::
34
35    simvx export web main.py -o raylib_tetris.html
36
37Attribution and upstream licence: see ``ATTRIBUTION.md`` and
38``UPSTREAM_LICENSE.md`` beside this file.
39"""
40
41from nodes.tetris_game import TetrisGame
42
43from simvx.graphics import App
44
45WIDTH, HEIGHT = 600, 600
46
47
48def main():
49    App(title="Tetris (raylib classic)", width=WIDTH, height=HEIGHT).run(TetrisGame())
50
51
52if __name__ == "__main__":
53    main()