Hextris¶
Rotate the hexagon to line up falling colour blocks.
▶ Run in browserUpstream: https://github.com/Hextris/hextris
Licence: this port's own code is offered under GPL-3.0-or-later, 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
Hextris (SimVX port)¶
SimVX port of Hextris, the hexagonal falling-block puzzle. Coloured blocks fall from six directions toward a central hexagon: rotate the hexagon so three or more blocks of one colour stack on a single face and they clear. Let any face stack eight blocks deep and the run ends.
Licensing: GPL-3.0-or-later, matching upstream. No upstream art is reused: the
board, blocks and HUD are drawn procedurally. See ATTRIBUTION.md.
Run¶
simvx examples run ports_hextris
simvx export web main.py -o hextris.html
Controls¶
Action |
Binding |
|---|---|
Rotate anticlockwise |
Left / A, or tap the left half |
Rotate clockwise |
Right / D, or tap the right half |
Speed the blocks up |
Down / S, or hold the pointer near the bottom |
Pause |
P |
Start / restart |
Enter / Space / R, or tap |
What this shows about SimVX¶
Immediate-mode 2D drawing. The whole board (hexagon, slices, block trapezoids, HUD, overlays) is one
on_drawbody usingpolygon,line,rectandtext. No sprites, no assets.Rect-aligned text. Titles, prompts and the controls strip are positioned with
text(rect=..., align="centre", fit_to_width=True)instead of hand-measured offsets, so they stay centred and readable at any size.A resize-aware layout. Drawing and hit-testing both derive from
tree.screen_size, with a uniform scale from the 800x800 design size, so the responsive web export stays centred at any aspect ratio.One input path for mouse and touch. The web runtime reports a touch as a left mouse button press at the touch position, so
Input.is_mouse_button_just_pressed(Mouse.LEFT)plus the pointer position covers desktop and mobile without a separate touch branch.Actions registered in the root’s ready path.
InputMap.add_actioncalls live inHextrisRoot.on_ready, not inmain(), becauseInputMapbelongs to a scene tree and none exists beforerun().
Upstream¶
The upstream JavaScript was used as a design reference only; all Python here was written from scratch.
Source files¶
File |
Summary |
Lines |
|---|---|---|
Hextris: Rotate the hexagon to line up falling colour blocks. |
54 |
|
Headless screenshot capture for Hextris. |
22 |
|
0 |
||
HextrisGame: the whole game in one immediate-mode 2D scene node. |
431 |
|
Hex geometry helpers for the board: angles, vertices, slices and blocks. |
89 |
Source¶
1#!/usr/bin/env python3
2# /// simvx
3# tags = ["port", "tier-0"]
4# upstream = "https://github.com/Hextris/hextris"
5# web = { width = 800, height = 800, responsive = true }
6# ///
7"""Hextris: Rotate the hexagon to line up falling colour blocks.
8
9Port of Hextris (https://github.com/Hextris/hextris, GPL-3.0-or-later) rebuilt
10on SimVX. Coloured blocks fall from six directions toward a central hexagon:
11rotate the hexagon so three or more blocks of one colour stack on a single face
12and they clear. Let any face stack eight blocks deep and the run ends.
13
14The board, blocks and HUD are drawn procedurally in ``on_draw`` (polygons,
15lines and rect-aligned text), the layout follows the live viewport size so the
16responsive web export stays centred, and every control has a pointer
17equivalent: web touches arrive as left clicks, so one code path serves mouse
18and touch.
19
20Run: simvx examples run ports_hextris
21Web export: simvx export web main.py -o hextris.html
22
23Controls:
24 Left / A, or tap the left half Rotate anticlockwise
25 Right / D, or tap the right half Rotate clockwise
26 Down / S, or hold near the bottom Speed the blocks up
27 P Pause
28 Enter / Space / R, or tap Start, and restart after a game over
29"""
30
31from nodes.game import HextrisGame # noqa: E402
32
33from simvx.core import InputMap, Key, Node
34from simvx.graphics import App # noqa: E402
35
36WIDTH, HEIGHT = 800, 800
37
38
39class HextrisRoot(Node):
40 """Root node: registers actions and hosts the game scene."""
41
42 def on_ready(self):
43 # Actions are registered here rather than in main(): InputMap belongs
44 # to a scene tree, and none exists before run().
45 InputMap.add_action("rotate_left", [Key.LEFT, Key.A])
46 InputMap.add_action("rotate_right", [Key.RIGHT, Key.D])
47 InputMap.add_action("speed_up", [Key.DOWN, Key.S])
48 InputMap.add_action("start", [Key.ENTER, Key.SPACE, Key.R])
49 InputMap.add_action("pause", [Key.P])
50 self.add_child(HextrisGame(name="HextrisGame"))
51
52
53if __name__ == "__main__":
54 App(width=WIDTH, height=HEIGHT, title="Hextris (SimVX port)").run(HextrisRoot())