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