AI guide
How to make and change Ludrel games with the AI tools (MCP server apps/mcp, or the built-in assistant).
The tools work on game folders under games/; every edit is validated, and games run headless so a change can be
proved before anyone plays it.
The loop
Section titled “The loop”- Look.
list_games, thenget_project_treeandread_fileforgame/game.json, the scene you will change, and the prefabs involved. For levels, readgame/levels/legend.json(the map characters). - Change data first. Prefer the specific tools:
update_prefab(merge component values),upsert_prefab,upsert_scene,add_entity,build_level(new levels),read_level+edit_level(change existing levels). Usewrite_filefor anything else, including code insrc/. An invalid document is refused with exact JSON pointers, and nothing is written; fix and retry. - Validate.
validate(addtypecheck: trueafter editing code). Fix every error. - Prove it.
run_headlesswith scriptedinputsandexpectassertions, e.g. “after 2 s holding right,player.Transform.x > 100” or “eventpickup:gemhappened”. Results include errors, event counts, named entities (position, velocity, health) and scene state. - Look again (optional, slower).
capture_screenshotshows a scene after scripted input.
Start a new game with create_game_from_template (template platformer), which creates games/<name>.
How a game is organised
Section titled “How a game is organised”game/game.json: display size, input actions (moveX,jump,down,pause,uiUp…), UI theme, assets (images, sprite sheets with animations, bitmap fonts,synthaudio), prefab list, scene list, entry scene.game/scenes/<id>.json: level, camera, background, music,systems(code behaviors),hud,menu,rules.game/levels/<id>.json: tilemap. Build new ones withbuild_levelfrom text rows instead of writing tile arrays. To change one,read_level(layers drawn as text, objects with tile positions, gids per tileset) and thenedit_levelwith operations:ground(auto-tiled terrain by cells orrect),paint/fill/floodFill(gids),place/move/update/removeobjects,resize, layer operations. They apply all or nothing and the result is validated. Creators make the same edits in the editor’s visual level view.game/prefabs/<id>.json: entity templates;componentsby name (see the component reference),tags, optionalextends(another prefab whose components are merged under these).game/audio/*.json: synthesized sound effects (kind: "sound") and songs (kind: "song").src/behaviors.ts: code. Every exported function is a behavior that scenes can list insystems.
Gameplay without code
Section titled “Gameplay without code”Built-in components (always active): PlatformerController (run, jump, maxJumps, enabled), Health,
ContactDamage (stompable), Patrol (walkers turn at walls and ledges), Hover (flyers: rangeX, rangeY,
period), Pickup (emits pickup:<kind>, can heal), Checkpoint, Lifetime, PlatformerAnimator, Trigger,
plus physics (Body, Collider) and visuals (Sprite, SpriteAnimation, Rect, Text, ParticleEmitter).
Rules connect events to actions in a scene:
- Events:
scene:start,controller:jump,pickup:<kind>,enemy:stomped,enemy:defeated,<name>:hurt,<name>:died,<name>:respawned,checkpoint:reached,trigger:<event>(fromTriggercomponents or level trigger objects),input:<action>(an input action was pressed),app:hidden(page lost focus), and anything a behavior emits. - Actions:
goToScene(fades),pushScene,popScene,restartScene,addToCounter(amountorfroma binding;scopesceneorsession),setCounter,playSound,playMusic,stopMusic,cameraShake,emit,respawn,setComponent(change fields of a named entity),banner,toggleSetting,saveGame. Any action takesdelayMs.
Bindings read values for HUD labels, menu labels, banners and assertions: game.<key> (scene state, e.g.
game.coins, game.coinTotal), session.<key> (kept across scenes), settings.sound, and <entity>.<Component>.<field>
for named entities (e.g. player.Health.hp). Labels use {binding}; HUD labels also take {value}.
Conventions and pitfalls
Section titled “Conventions and pitfalls”- Names: ids are lowercase with dashes (
level-2); components are PascalCase; input actions camelCase. - The player must be named
player(level legendP, oridon the spawn) for cameras, HUD and rules. - Spawn positions are the top-left of the entity’s sprite; colliders are offset inside it.
- A new scene must be listed in
game.json(upsert_scenedoes that) and reachable (goToScenefrom another scene’s rule or menu). - Simulation is deterministic: never use
Math.randomin behaviors; use theGameRngresource. - Use the documented binding paths. If
run_headlessreports a binding asundefined, the entity is not named or the scene state key was never set. - Keep changes small and validate after each one;
run_headlesscosts a fraction of a second.