Snake
A complete arcade loop on a 50×50 WebGPU board. The simulation owns movement and collisions; Svelte owns the menus, score, and touch controls.
What this demonstrates
The example keeps gameplay in a small, deterministic state machine and uses the existing WebGPU shape commands for every board element.
The typed GameHost bridge publishes readonly state to Svelte, while commands provide the narrow control surface for menus and
touch input. Starting, resuming, restarting, or changing direction through the D-pad returns keyboard focus to the board, so arrow keys stay
with the game instead of scrolling the documentation page.
Public shape
type SnakeState = Readonly<{
status: "start" | "playing" | "paused" | "game-over";
snake: readonly GridPoint[];
fruit: GridPoint | null;
score: number;
}>;
<GameHost initial_state={initial_state} {commands} create={create_snake}>
{#snippet children(view)}
<output>{view.state.score}</output>
{/snippet}
</GameHost> Scope and limitations
The board wraps no edges, the score lasts only for the current run, and the example supports keyboard and touch input. Rebinding, gamepad controls, persistent scores, audio, and network play remain outside this focused example.