Build games with Astra: Lantern Run arena with lanterns, sentinel patrols and passing node:test output

When you build games with Astra, the first version always looks more finished than it is. The arena renders, the player glides around, the lanterns glow. Then you stand next to a sentinel for three seconds and lose 150 points, or a frame stutters and you walk straight through a lantern without picking it up.

That gap is what I care about with any coding agent. The agent can produce a convincing Three.js scene in minutes. Whether the game underneath follows its own rules is a separate question, and the screen won’t answer it.

So for Lantern Run, a tiny collect-the-lanterns game, I wrote the rules first: about 100 lines of plain JavaScript with no Three.js and no DOM, 12 tests, and a scripted player that ran 50 seeded levels. Only after that does the agent get the renderer. Everything below is that code and its real output.


Start from what the player should feel

OpenAI’s own guide for game developers opens with the experience, not the tech stack. Its example, Void Explorer, is defined by one continuous trip from space down to a planet’s surface, and the architecture follows from that. I think this is the most useful habit in the whole workflow, and it scales down well.

For Lantern Run the experience fits in one sentence: a short, slightly tense dash to grab ten lanterns while dodging two patrols. Every rule should serve that sentence. If a rule makes the run feel unfair (losing points every frame you touch a sentinel) or pointless (a timer you can never run out of), it’s wrong, however clean the code is.

Then write that down as a contract the agent can’t drift from:

Game: Lantern Run
Goal: collect 10 lanterns within 90 seconds.
Controls: WASD / arrow keys move the player on the X/Z plane.
Rules:
- A lantern disappears once collected and adds 100 points.
- Two sentinels patrol fixed routes.
- Contact removes 50 points, then 1 second of grace.
- The score never drops below 0.
- Win when all lanterns are collected. Lose when the timer hits 0.
Technical:
- Rules live in game.mjs: plain data in, plain data out.
- The renderer reads game state and never changes it.
- Primitive geometry only. No physics engine, no external assets.

The non-goals matter as much as the goals. They stop a promising prototype from turning into six half-built systems.

To build games with Astra, keep the rules out of the renderer

The whole game is one state object and one function that moves it forward. Here is the core of game.mjs:

function step(g, dt, input) {
  const r = g.rules;
  g.time += dt;

  const len = Math.hypot(input.x, input.z);
  if (len > 0) {
    const half = r.arena / 2;
    g.player.x = clamp(g.player.x + (input.x / len) * r.playerSpeed * dt, -half, half);
    g.player.z = clamp(g.player.z + (input.z / len) * r.playerSpeed * dt, -half, half);
  }
  for (const s of g.sentinels) moveSentinel(s, dt);

  for (const l of g.lanterns) {
    if (!l.collected && near(g.player, l, r.pickupRadius)) {
      l.collected = true;
      g.collected += 1;
      g.score += r.lanternPoints;
    }
  }
  if (g.time >= g.graceUntil && g.sentinels.some((s) => near(g.player, s, r.hitRadius))) {
    g.hits += 1;
    g.score = Math.max(0, g.score - r.hitPenalty);
    g.graceUntil = g.time + r.graceSeconds;
  }

  if (g.collected === r.lanterns) g.phase = "won";
  else if (g.time >= r.duration) g.phase = "lost";
}

// One rendered frame. Long frames are split so nothing is skipped over.
export function update(g, frameSeconds, input = { x: 0, z: 0 }, { split = true } = {}) {
  let left = frameSeconds;
  while (left > 1e-9 && g.phase === "playing") {
    const dt = split ? Math.min(left, g.rules.maxStep) : left;
    step(g, dt, input);
    left -= dt;
  }
  return g;
}

Two details are easy to miss. The input is normalised, so pressing W and D together doesn’t make you 41% faster. And update refuses to simulate more than 0.05 seconds in one go: a long frame becomes several short steps. The next section shows why that line exists.

Because nothing here touches the scene graph, I can run the game thousands of times a second in Node. That’s what makes the tests cheap.

Twelve tests to write before you build games with Astra

I used Node’s built-in node:test runner, so there’s nothing to install. Each test sets up a small hand-built scene (one lantern here, one parked sentinel there) and checks one rule. This is the output of node --test:

✔ walking onto a lantern collects it once and scores 100
✔ collecting the last lantern wins
✔ the timer runs out and the game is lost
✔ nothing changes after the game ends
✔ standing on a sentinel costs 50 once per second, not every frame
✔ the score never goes below zero
✔ diagonal movement is not faster than straight movement
✔ the player cannot leave the arena
✔ a 0.5 s frame hitch walks straight past a lantern unless the frame is split
✔ the same hitch lets the player pass through a sentinel untouched
✔ a seed always builds the same level, and a playthrough replays exactly
✔ the scripted bot wins every one of 50 seeded levels
ℹ tests 12
ℹ pass 12
ℹ fail 0
ℹ duration_ms 77.779834

The grace-period test is the one I’d write first in any game with damage. Standing still on a sentinel for 2.5 seconds should cost exactly three hits (at 0, 1 and 2 seconds), not 150 hits at 60 frames a second:

test("standing on a sentinel costs 50 once per second, not every frame", () => {
  const g = scene({ lanterns: [{ x: 9, z: 9 }], sentinels: [{ x: 0, z: 0 }] });
  g.score = 500;
  for (let i = 0; i < 60 * 2.5; i++) update(g, 1 / 60);
  assert.equal(g.hits, 3);
  assert.equal(g.score, 350);
});

“Nothing changes after the game ends” sounds trivial, but it catches a whole family of bugs: a timer that keeps counting on the win screen, or a lantern collected after you’ve already lost.

The frame-hitch bug the tests caught

Browsers stall. A tab comes back from the background, garbage collection kicks in, and one frame lasts half a second. At a speed of 6 units a second, the player jumps 3 units in that one step. A lantern with a 0.8-unit pickup radius sitting 1.5 units ahead is simply jumped over:

test("a 0.5 s frame hitch walks straight past a lantern unless the frame is split", () => {
  const unsplit = scene({ lanterns: [{ x: 1.5, z: 0 }, { x: -9, z: -9 }] });
  update(unsplit, 0.5, { x: 1, z: 0 }, { split: false });
  assert.equal(unsplit.collected, 0); // jumped from x=0 to x=3

  const split = scene({ lanterns: [{ x: 1.5, z: 0 }, { x: -9, z: -9 }] });
  update(split, 0.5, { x: 1, z: 0 });
  assert.equal(split.collected, 1);
});

The same hitch works the other way too: the player passes clean through a sentinel and takes no hit. One bug makes the game feel broken, the other makes it exploitable.

A common fix is to clamp the frame time, something like Math.min(delta, 0.05). That stops the tunnelling, but it quietly throws time away: a 0.5-second stall advances the game by only 0.05 seconds, so the timer and the patrols fall behind the wall clock. Splitting the frame into 0.05-second steps keeps both the collisions and the clock honest. Put a cap on the loop if you’re worried about a frame that lasts ten seconds.

The screen can’t tell you whether the game follows its own rules. A test can, in milliseconds.

Repeatable test scenes: seed the level

The OpenAI guide leans on repeatable test scenes and browser checks so the agent can reproduce a problem instead of guessing from a screenshot. The cheapest version of that is a seed. createGame(seed) places the lanterns with a small seeded random generator, so level 42 is always level 42:

export function createGame(seed = 1, rules = RULES) {
  const rand = seeded(seed);
  const half = rules.arena / 2 - 1;
  const lanterns = Array.from({ length: rules.lanterns }, (_, i) => ({
    id: i,
    x: (rand() * 2 - 1) * half,
    z: (rand() * 2 - 1) * half,
    collected: false,
  }));
  // ...sentinels on fixed routes, player at the origin
}

With that in place, a bug report becomes “seed 17, frame 412” rather than “sometimes the lantern doesn’t count”. You can hand exactly that to the agent and it can replay the same run.

I also wrote a scripted player, bot.mjs, about 40 lines. Each frame it walks towards the nearest lantern and steps away from any sentinel closer than 2.5 units. It’s not clever, and that’s the point: it’s a repeatable stand-in for a player.

What 50 playthroughs said about the design

I ran the bot on 50 seeded levels under five different settings. Total run time: about a tenth of a second.

SettingWonMedian timeAvg hitsAvg score
Dodging, 60 fps50/507.93 s0.1993
No dodging, 60 fps50/507.05 s0.8961
Dodging, 30 fps50/508.00 s0.1996
0.5 s hitch every 20 frames, split50/508.78 s0.4981
0.5 s hitch every 20 frames, not split50/509.80 s0.3984

Three things stand out.

The timer isn’t doing anything. A bot that walks in straight lines finishes in about 8 seconds out of 90. A person will be slower, steering and looking at the camera, but probably not ten times slower. The “slightly tense” part of my one-sentence experience isn’t there yet. Either the timer comes down or the arena and patrols get harder, and now I can test each change in a second instead of play-testing it by feel.

Frame rate doesn’t change the result. At 30 and 60 fps the bot wins in about the same time with the same hits. That’s the delta-time handling working, checked rather than assumed.

Unsplit hitches show up as fewer hits, not more. With the split turned off, the bot took 0.3 hits on average against 0.4 with it on. That looks like an improvement until you remember the tunnelling test: some of those missing hits are the player phasing through sentinels. It’s a good example of a number that only makes sense next to a test that explains it.

How to build games with Astra: hand it the renderer, not the rules

This is the point where it pays to build games with Astra rather than by hand: once the rules are pinned down, the agent’s job becomes much narrower, and narrow tasks are where coding agents do best. This is the prompt I’d use for the Three.js layer:

Build the browser renderer for Lantern Run.
- game.mjs holds all rules. Do not edit it.
- Each frame: update(game, clock.getDelta(), readInput()), then draw from game state.
- Use renderer.setAnimationLoop, not requestAnimationFrame.
- Primitive geometry: plane ground, capsule player, cylinder lanterns, sphere sentinels.
- Reuse one geometry and one material per object type.
- HUD shows score, time left and lanterns collected, as text, not only colour.
- "node --test" must still pass. Add no new dependencies besides three.
Return the changed files and a short list of what to check by hand.

The glue it should produce is tiny, because all the decisions already live in game.mjs:

const clock = new THREE.Clock();
const game = createGame(seed);

renderer.setAnimationLoop(() => {
  update(game, clock.getDelta(), readInput());
  draw(game); // move meshes to match state, hide collected lanterns, update HUD
  renderer.render(scene, camera);
});

Three.js recommends setAnimationLoop over managing requestAnimationFrame yourself, and its WebGLRenderer documentation also covers renderer.info, which reports draw calls and triangles. Ask the agent to print those in a debug overlay: they’re the performance version of a test.

When something feels wrong in the browser, the feedback should be just as specific. “Movement feels off” gives the agent nothing. “Seed 17: the bot test passes, but in the browser the player moves faster on my 120 Hz monitor; check that draw() doesn’t move the player itself” points at the exact seam between the tested rules and the untested renderer.

Spend detail only near the player

Void Explorer has thousands of planets, and the guide describes keeping them as compact descriptions rather than thousands of detailed meshes, generating terrain in more detail as the player gets close, with several levels of detail between far and near. That principle is the same at Lantern Run’s scale, just with smaller numbers:

  • Cap the pixel ratio (for example Math.min(devicePixelRatio, 2)) instead of rendering at whatever a high-density screen asks for.
  • Create geometry and materials once and reuse them. Never build meshes, vectors or DOM nodes inside the frame loop.
  • Keep anything the player can’t reach cheap: flat colour, low polygon counts, no shadows.
  • Test on the slowest device you have before calling the prototype done.

Only add models and animation after the loop works, and check every asset for rights, file size and scale. Three.js plays animation through AnimationMixer, but animation should decorate an interaction you’ve already proven, not hide one you haven’t.

Accessibility belongs in the first playable build too: clear instructions, enough contrast, a pause and restart, keyboard controls, and danger shown by shape or motion as well as colour.

A checklist before you build games with Astra past the grey box

This is the list I run through before letting the agent add anything beyond primitive shapes:

  1. The player experience fits in one sentence, and every rule serves it.
  2. The rules run without the renderer, in plain functions I can call from a test.
  3. There’s a test for each rule, including the boring ones: once-only pickups, the grace period, nothing changing after the game ends.
  4. Long frames are split, and a test proves a hitch can’t skip a pickup or a hit.
  5. Levels come from a seed, so any bug can be replayed exactly.
  6. A scripted player has run a few dozen levels, and I’ve looked at what the numbers say about difficulty.
  7. The agent’s prompt says which files it may not touch and which command must still pass.

OpenAI’s Playco case study reports three themed prototypes built from one grey-box foundation in Unity and Godot. That’s a vendor-reported result, but it fits what I’d expect: the speed comes from a solid base that the agent varies, not from one perfect prompt. If you want to see what other people have made, I’ve collected games made with Astra and what each one teaches. For the model itself, see what GPT-6 Astra’s full results table shows.

The rules for a small game fit in 100 lines. Writing them yourself, with tests, is the cheapest hour you’ll spend on the project, and it’s what lets you trust everything the agent builds on top.


Further reading

Leave A comment

Are you human? Please solve:Captcha