Asteroids (raylib classic)¶
vector ship physics, screen wrap, splitting rocks.
▶ 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
A SimVX re-implementation of the Asteroids sample from raylib-games by Ian Eito, Albert Martos and Ramon Santamaria (zlib/libpng, see ATTRIBUTION.md). Every pixel is drawn at runtime with the immediate-mode 2D API: line outlines for the ship and the rocks, rect bullets and particle bursts, text for the HUD and the menus. It shows a dynamic node driving per-frame redraw, input actions declared on the scene root, wrap-around movement, rocks splitting large to medium to small, and a playfield that follows the window size via viewport_size.
Run interactively::
simvx examples run ports_raylib_asteroids
Headless smoke test (writes two frames into screenshots/)::
simvx examples run ports_raylib_asteroids --test
Web export::
simvx export web main.py -o raylib_asteroids.html
Controls¶
Up / W: thrust
Left / A, Right / D: rotate
Space: shoot
Controller or the on-screen pad: the left stick points the nose, A thrusts, B fires
Hold the mouse button or touch: steer towards the pointer, thrust and fire
Space, R, Enter, A, Start or a click / tap: start, and restart after a game over
Esc: quit
Source files¶
File |
Summary |
Lines |
|---|---|---|
Asteroids (raylib classic): vector ship physics, screen wrap, splitting rocks. |
77 |
|
0 |
||
0 |
||
Asteroids: port of raylib-games/classics/src/asteroids.c (zlib/libpng). |
455 |
Source¶
1#!/usr/bin/env python3
2# /// simvx
3# tags = ["port", "tier-0"]
4# upstream = "https://github.com/raysan5/raylib-games/tree/master/classics/src"
5# web = { width = 800, height = 600, responsive = true }
6# ///
7"""Asteroids (raylib classic): vector ship physics, screen wrap, splitting rocks.
8
9A SimVX re-implementation of the Asteroids sample from raylib-games by Ian Eito,
10Albert Martos and Ramon Santamaria (zlib/libpng, see ATTRIBUTION.md). Every pixel
11is drawn at runtime with the immediate-mode 2D API: line outlines for the
12ship and the rocks, rect bullets and particle bursts, text for the HUD
13and the menus. It shows a dynamic node driving per-frame redraw, input actions
14declared on the scene root, wrap-around movement, rocks splitting large to
15medium to small, and a playfield that follows the window size via viewport_size.
16
17Run interactively::
18
19 simvx examples run ports_raylib_asteroids
20
21Headless smoke test (writes two frames into ``screenshots/``)::
22
23 simvx examples run ports_raylib_asteroids --test
24
25Web export::
26
27 simvx export web main.py -o raylib_asteroids.html
28
29Controls
30--------
31- Up / W: thrust
32- Left / A, Right / D: rotate
33- Space: shoot
34- Controller or the on-screen pad: the left stick points the nose, A thrusts,
35 B fires
36- Hold the mouse button or touch: steer towards the pointer, thrust and fire
37- Space, R, Enter, A, Start or a click / tap: start, and restart after a game
38 over
39- Esc: quit
40"""
41
42# /// script
43# requires-python = ">=3.14"
44# dependencies = ["simvx-core", "simvx-graphics", "numpy", "pillow"]
45# ///
46
47from __future__ import annotations
48
49import sys
50
51from nodes.asteroids_game import AsteroidsGame # noqa: E402
52
53from simvx.graphics import App # noqa: E402
54
55
56def main():
57 test_mode = "--test" in sys.argv
58 # The startup window size; the playfield follows the window from there on.
59 app = App(width=800, height=600, title="Asteroids (raylib classic)", visible=not test_mode)
60 if test_mode:
61 from pathlib import Path
62
63 from simvx.graphics import save_png
64
65 out = Path(__file__).resolve().parent / "screenshots"
66 out.mkdir(exist_ok=True)
67 frames = app.run_headless(AsteroidsGame(), frames=120, capture_frames=[60, 119])
68 for idx, n in enumerate([60, 119]):
69 save_png(frames[idx], out / f"frame_{n}.png")
70 print(f"wrote frame_{n}.png")
71 app.quit()
72 return
73 app.run(AsteroidsGame())
74
75
76if __name__ == "__main__":
77 main()