Write the GALAGA tutorial chapters and the repeated-host-calls guide
docs/20 builds the engine and the boundary: the startup order, the
starfield, actors and collision, booting a DEF-only script, the issue #8
mode workaround, the custom update hook, first light, screens, and the
headless harness. docs/21 builds the three shared structures and the AI:
the host type tables, the actor binding, the randomness route around
issue #16, the measured case against structure arguments (issue #36),
the three language rules that shape the script, the maneuvers, the
argued formation decision, the script-death policy, and the interop
proof. Every fenced block runs under tests/docs_examples.sh in both
build configurations; five new preludes carry the C fragments.
docs/10 gains the 'Calling a function every frame' section the chapters
lean on: the per-call akbasic_environment_zero() rule, the set_mode(RUN)
workaround, the clear_error() revival, and the case for rebinding over
structure arguments. Index rows and chapter counts updated.
Co-authored-by: andrew <andrew@aklabs.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XiGgpHuXUm2mR4Wzndw3dc
2026-08-04 08:47:43 -04:00
|
|
|
/*
|
|
|
|
|
* Prelude for the interpreter-facing fragments in docs/20: the boot sequence,
|
|
|
|
|
* the ADDEM proof and the rebind-call-reset protocol, shown as runs of CATCH
|
|
|
|
|
* calls. The statics are the ones examples/galaga/script.c keeps; the locals
|
|
|
|
|
* are the superset every fragment draws from, void-cast in the postlude so an
|
|
|
|
|
* unused one is not a warning.
|
|
|
|
|
*/
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
|
|
|
|
|
#include <akerror.h>
|
|
|
|
|
#include <akstdlib.h>
|
|
|
|
|
|
|
|
|
|
#include <akgl/actor.h>
|
|
|
|
|
|
|
|
|
|
#include <akbasic/environment.h>
|
|
|
|
|
#include <akbasic/error.h>
|
|
|
|
|
#include <akbasic/host.h>
|
|
|
|
|
#include <akbasic/runtime.h>
|
|
|
|
|
#include <akbasic/sink.h>
|
|
|
|
|
|
|
|
|
|
typedef struct galaga_docs_Enemy
|
|
|
|
|
{
|
|
|
|
|
int32_t kind;
|
|
|
|
|
int32_t state;
|
|
|
|
|
float homex;
|
|
|
|
|
float homey;
|
|
|
|
|
float t;
|
|
|
|
|
int32_t hp;
|
|
|
|
|
int32_t fire;
|
|
|
|
|
float rnd;
|
|
|
|
|
} galaga_docs_Enemy;
|
|
|
|
|
|
2026-08-04 09:22:43 -04:00
|
|
|
typedef struct galaga_docs_Shared
|
|
|
|
|
{
|
|
|
|
|
float playerx;
|
|
|
|
|
float playery;
|
|
|
|
|
int32_t wave;
|
|
|
|
|
float rnd;
|
|
|
|
|
} galaga_docs_Shared;
|
|
|
|
|
|
Write the GALAGA tutorial chapters and the repeated-host-calls guide
docs/20 builds the engine and the boundary: the startup order, the
starfield, actors and collision, booting a DEF-only script, the issue #8
mode workaround, the custom update hook, first light, screens, and the
headless harness. docs/21 builds the three shared structures and the AI:
the host type tables, the actor binding, the randomness route around
issue #16, the measured case against structure arguments (issue #36),
the three language rules that shape the script, the maneuvers, the
argued formation decision, the script-death policy, and the interop
proof. Every fenced block runs under tests/docs_examples.sh in both
build configurations; five new preludes carry the C fragments.
docs/10 gains the 'Calling a function every frame' section the chapters
lean on: the per-call akbasic_environment_zero() rule, the set_mode(RUN)
workaround, the clear_error() revival, and the case for rebinding over
structure arguments. Index rows and chapter counts updated.
Co-authored-by: andrew <andrew@aklabs.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XiGgpHuXUm2mR4Wzndw3dc
2026-08-04 08:47:43 -04:00
|
|
|
static akbasic_Runtime SCRIPT;
|
|
|
|
|
static akbasic_TextSink SINK;
|
|
|
|
|
static akbasic_StdioSink SINKSTATE;
|
|
|
|
|
static char SOURCE[16384];
|
|
|
|
|
|
2026-08-04 09:22:43 -04:00
|
|
|
static galaga_docs_Enemy SCRATCH_ENEMY;
|
|
|
|
|
static akgl_Actor SCRATCH_ACTOR;
|
|
|
|
|
static galaga_docs_Shared galaga_shared;
|
|
|
|
|
|
|
|
|
|
static const akbasic_HostField ENEMY_FIELDS[] = {
|
|
|
|
|
AKBASIC_HOST_FIELD( galaga_docs_Enemy, kind, "KIND#", AKBASIC_HOSTFIELD_INT32 )
|
|
|
|
|
};
|
|
|
|
|
static const akbasic_HostType ENEMY_TYPE = {
|
|
|
|
|
"ENEMY", sizeof(galaga_docs_Enemy), ENEMY_FIELDS, 1
|
|
|
|
|
};
|
|
|
|
|
static const akbasic_HostField ACTOR_FIELDS[] = {
|
|
|
|
|
AKBASIC_HOST_FIELD( akgl_Actor, x, "X%", AKBASIC_HOSTFIELD_FLOAT )
|
|
|
|
|
};
|
|
|
|
|
static const akbasic_HostType ACTOR_TYPE = {
|
|
|
|
|
"ACTOR", sizeof(akgl_Actor), ACTOR_FIELDS, 1
|
|
|
|
|
};
|
|
|
|
|
static const akbasic_HostField GAME_FIELDS[] = {
|
|
|
|
|
AKBASIC_HOST_FIELD( galaga_docs_Shared, wave, "WAVE#", AKBASIC_HOSTFIELD_INT32 )
|
|
|
|
|
};
|
|
|
|
|
static const akbasic_HostType GAME_TYPE = {
|
|
|
|
|
"GAME", sizeof(galaga_docs_Shared), GAME_FIELDS, 1
|
|
|
|
|
};
|
|
|
|
|
|
Write the GALAGA tutorial chapters and the repeated-host-calls guide
docs/20 builds the engine and the boundary: the startup order, the
starfield, actors and collision, booting a DEF-only script, the issue #8
mode workaround, the custom update hook, first light, screens, and the
headless harness. docs/21 builds the three shared structures and the AI:
the host type tables, the actor binding, the randomness route around
issue #16, the measured case against structure arguments (issue #36),
the three language rules that shape the script, the maneuvers, the
argued formation decision, the script-death policy, and the interop
proof. Every fenced block runs under tests/docs_examples.sh in both
build configurations; five new preludes carry the C fragments.
docs/10 gains the 'Calling a function every frame' section the chapters
lean on: the per-call akbasic_environment_zero() rule, the set_mode(RUN)
workaround, the clear_error() revival, and the case for rebinding over
structure arguments. Index rows and chapter counts updated.
Co-authored-by: andrew <andrew@aklabs.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XiGgpHuXUm2mR4Wzndw3dc
2026-08-04 08:47:43 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *galaga_docs_fragment(galaga_docs_Enemy *enemy, akgl_Actor *actor, float dt);
|
|
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *galaga_docs_fragment(galaga_docs_Enemy *enemy, akgl_Actor *actor, float dt)
|
|
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
|
|
|
|
akbasic_Value args[2];
|
|
|
|
|
akbasic_Value *argp[2];
|
|
|
|
|
akbasic_Value dtval;
|
|
|
|
|
akbasic_Value *result = NULL;
|
|
|
|
|
|
|
|
|
|
ATTEMPT {
|