Top-down games: worlds, NPCs, dialogue, quests, items, languages
Phase 5a added these (ADR 0024). Start from the template: pnpm create-game my-game --template topdown. In the
platform editor, use Start from the top-down template. Everything below is data, validated like every other
document, so creators, content packs and AI tools can write it.
Movement
Section titled “Movement”TopDownControllermoves an entity in eight directions from two axis actions (moveX,moveY). ListtopDownControllerin the scene’ssystems.TopDownAnimatorplayswalk-<facing>/idle-<facing>animations, with facingdown,up,leftorright.- Set gravity to zero in
game.json:"physics": { "gravity": { "x": 0, "y": 0 } }.
Worlds (large maps)
Section titled “Worlds (large maps)”A scene can have "world": "world.json" instead of a level. A world document lists a grid of chunks, and each
chunk is an ordinary level of chunkWidth × chunkHeight tiles. Chunk levels work in the level editor, the AI level
tools and packs.
Chunks within streamRadius of the camera’s target are loaded; the others unload. Two things to know:
- Objects removed while their chunk was loaded (collected, defeated) stay gone.
- Cells of unloaded chunks count as solid, so nothing walks into them.
NPC brains
Section titled “NPC brains”An NPC has a Brain component naming a brain document (game/ai/<id>.json, listed in game.json brains).
A state machine. Each state has an activity or a behaviour tree.
- Activities:
idle,moveTo,wander,follow,flee,wait,say(a speech bubble) anddo(rule actions). - A transition fires on an event (
on), a condition (if), time in the state (after), or when the activity finishes (done).
A behaviour tree.
- Composites:
sequence,selector,parallel. - Decorators:
inverter,succeeder,repeat,cooldown. - Leaves:
condition, andactionwith any activity.
NPCs walk around walls with A* over tile collision. Brains are deterministic (seeded randomness, fixed step).
Talking, dialogue and quests
Section titled “Talking, dialogue and quests”Interactable: pressinginteractnear it emitstalked:<entity name>and opens itsdialogue. It showspromptwhile the player is in range.- Dialogues (
game/dialogues/*.json): nodes have a speaker, text,doactions andchoices.branchesjump to another node when a condition holds. The built-in dialogue box pauses play;uiUp/uiDownpick a choice anduiConfirmcontinues. - Quests (
game/quests/*.json): steps complete in order, on an event (when.event, counted) or a condition (when.if). Each step can rundoactions, and the last one runsrewards. Progress emitsquest:started:<id>,quest:step:<id>andquest:done:<id>. ThequestHUD widget shows the current step. - Actions:
startDialogue,startQuest,giveItem,takeItem,useItemandsetLanguage.
Conditions
Section titled “Conditions”These are used by rules (if), dialogue choices and branches, quest steps, and brains:
{ "value": "session.coins", "op": ">=", "than": 3 }{ "hasItem": "key", "count": 1 }{ "quest": "cave", "is": "active", "step": "find" }{ "near": "player", "within": 48 }(brains only){ "chance": 0.5 }{ "all": [...] },{ "any": [...] },{ "not": {...} }
Items are listed in game.json items, each with:
- a name;
- an icon (and frame);
stackableandmax;useactions, andconsumablefor items used up byuseItem.
A Pickup with "item": "<id>" adds the item when collected. Bindings:
items.<id>: how many the player carries;quest.<id>: the quest’s state;quest.<id>.step: its current step.
Inventory and quests live in the session, and saveGame saves them.
Languages
Section titled “Languages”game/locales/<lang>.json are string tables, listed in game.json localization. Any text field may say @key;
inline { "en": ..., "fr": ... } maps still work.
The player’s language comes from the browser. setLanguage (a code, or next to cycle) changes it and remembers
it; settings.language binds it. Missing keys fall back to the default language. Bitmap fonts draw lowercase with
capitals; the template’s font has accented capitals for French.
See the recipe recipes/npc-quest.md and templates/topdown.