/*
 * Prelude for statement-context fragments in docs/20: runs of CATCH calls
 * from the galaga frame loop, shown without their scaffolding because the
 * ATTEMPT protocol is the scaffolding. Same policy as hostcalls.pre.
 */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>

#include <akerror.h>
#include <akstdlib.h>

#include <akgl/actor.h>
#include <akgl/controller.h>
#include <akgl/draw.h>
#include <akgl/game.h>
#include <akgl/heap.h>
#include <akgl/renderer.h>
#include <akgl/ui.h>

#include <akbasic/error.h>
#include <akbasic/runtime.h>

typedef enum
{
    GALAGA_SCREEN_TITLE = 0,
    GALAGA_SCREEN_PLAY,
    GALAGA_SCREEN_GAMEOVER,
    GALAGA_SCREEN_VICTORY
} galaga_Screen;

struct galaga_docs_Game
{
    galaga_Screen screen;
    float dt;
    akgl_Actor *player;
};
extern struct galaga_docs_Game galaga_game;
extern akgl_Actor *galaga_enemy_actors[40];

akerr_ErrorContext AKERR_NOIGNORE *declare_title(void);
akerr_ErrorContext AKERR_NOIGNORE *declare_play(void);
akerr_ErrorContext AKERR_NOIGNORE *declare_end(void);
akerr_ErrorContext AKERR_NOIGNORE *galaga_docs_fragment(void);
akerr_ErrorContext AKERR_NOIGNORE *galaga_docs_fragment(void)
{
    PREPARE_ERROR(errctx);
    SDL_Event event;

    ATTEMPT {
