Skip to content

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.

  • TopDownController moves an entity in eight directions from two axis actions (moveX, moveY). List topDownController in the scene’s systems.
  • TopDownAnimator plays walk-<facing> / idle-<facing> animations, with facing down, up, left or right.
  • Set gravity to zero in game.json: "physics": { "gravity": { "x": 0, "y": 0 } }.

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.

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) and do (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, and action with any activity.

NPCs walk around walls with A* over tile collision. Brains are deterministic (seeded randomness, fixed step).

  • Interactable: pressing interact near it emits talked:<entity name> and opens its dialogue. It shows prompt while the player is in range.
  • Dialogues (game/dialogues/*.json): nodes have a speaker, text, do actions and choices. branches jump to another node when a condition holds. The built-in dialogue box pauses play; uiUp/uiDown pick a choice and uiConfirm continues.
  • Quests (game/quests/*.json): steps complete in order, on an event (when.event, counted) or a condition (when.if). Each step can run do actions, and the last one runs rewards. Progress emits quest:started:<id>, quest:step:<id> and quest:done:<id>. The quest HUD widget shows the current step.
  • Actions: startDialogue, startQuest, giveItem, takeItem, useItem and setLanguage.

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);
  • stackable and max;
  • use actions, and consumable for items used up by useItem.

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.

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.