A GALAGA-style fixed shooter whose engine is C on libakgl (null physics) with the interpreter embedded as the scripting engine that owns every enemy's behavior. One DEF-only script is called per enemy per frame through a custom akgl_Actor update hook; SELF@, ACTOR@ and GAME@ are host bindings, so the script reads and writes the engine's real memory -- the boss even swaps its own damage sprite by raising an actor state bit from BASIC. Bullets, collision, scoring and screens stay C. Structure arguments were measured and rejected for the per-frame path: each pointer parameter spends a value-pool slot the pool never reclaims, 1,015 calls to exhaustion against an unbounded rebind (issue #36). Built when AKBASIC_WITH_AKGL=ON. Two CTest entries: a 600-frame headless autoplay run under the dummy SDL drivers, and an interop round-trip test that links the real script.c and galaga.bas and pins the four boundary claims, 24,000 sustained calls among them. docs_galaga_figures regenerates the two checked-in figures. Art is Kenney CC0, byte for byte, with provenance. Co-authored-by: andrew <andrew@aklabs.net> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XiGgpHuXUm2mR4Wzndw3dc
GALAGA — a C engine with akbasic embedded as its enemy brain
A GALAGA-style fixed shooter whose core engine is C on libakgl, with akbasic
linked in as the scripting engine that owns every enemy's behavior. One BASIC
script — galaga.bas, nothing but DEF functions and an END — is called
once per enemy per frame through a custom akgl_Actor update hook. Bullets,
collision, scoring and screens are C forever; everything an enemy decides is
BASIC.
This is the checked-in example behind two tutorial chapters, and the chapters are the intended way in:
- Chapter 20 — the engine and the boundary: from an empty file to a C game that boots a script and hands one actor to BASIC.
- Chapter 21 — the data
structures and the AI: from
SELF@to a full attacking wave.
It is an academic exercise demonstrating how such an embed is done, not a claim that it is the best way to write a GALAGA.
Building and running
The example builds when both example and graphics builds are on:
cmake -S . -B build-akgl -DAKBASIC_WITH_AKGL=ON
cmake --build build-akgl --target akbasic_example_galaga
build-akgl/akbasic_example_galaga
| Key | Does |
|---|---|
| Left / Right | move the ship |
| Space | fire (two shots on screen, the classic rule) |
| Return | choose a menu entry |
Flags
akbasic_example_galaga [--assets DIR] [--script PATH] [--frames N]
[--autoplay] [--screenshot PATH] [--screenshot-frame N]
--script points at a different enemy script, which is the whole point of the
architecture: edit galaga.bas, run again, no rebuild. --frames N with
--autoplay is the headless smoke test CI runs under the dummy SDL drivers;
the final log line reports frames, score, kills and shots per kind, and the
script-error count — a wave of dumb enemies still exits 0, and that count is
how you notice.
The files
| File | Owns |
|---|---|
galaga.h |
the shared structs — the whole boundary in one header |
main.c |
startup order, the frame loop, screens, the starfield |
script.c |
everything that touches the interpreter |
enemies.c |
wave table, formation grid, the enemy update hook |
player.c |
the ship, both bullet kinds, every collision |
galaga.bas |
every decision an enemy makes |
interop_test.c |
round-trip proof the boundary works, run by CTest |
assets/ |
sprite/character JSON, and Kenney CC0 art under assets/art/ |