logo
By Lawrence

5 minutes

Death, Linger, Restart

Course 2 left you a loose end and told you it was deliberate. When you die, destroyShip freezes the ship, hides it, silences the gun, tags it dead, and attaches a RespawnTimer. Nothing in the entire combat set reads that timer. You sit there, invisible and stationary, for as long as you care to wait.

That was the right place to stop, because "what happens after a death" is not a question the damage code gets to answer. Here is the component that does:

        "RoundReset": {
          "on": ["spaceshooter.player.killed"],
          "lingerSeconds": 3
        }

Naming the death you mean

src/components/RoundReset/RoundReset.defs.ts
export interface RoundResetInput {
  /** Seconds the wreck stays on screen before the scene rebuilds. */
  lingerSeconds?: number;
  /** Event names that end the round. */
  on?: string[];
  /** Live phase — `lingering` once a death has landed. */
  phase?: RoundPhase;
  /** Seconds left in the linger. Meaningless while `running`. */
  remaining?: number;
}

on defaults to ['game.player.died'], the cross-game name every genre in the library can agree on. Your space shooter already emits spaceshooter.player.killed for the same fact, and has since Course 2.

Two ways to reconcile that. Emit game.player.died as well, from the kill path. Now one death produces two events, every future listener has to know which one is real, and someone subscribes to both and counts a death twice. Or point the component at the name your game already uses, in the scene, in one line. The second is why on is a list of strings instead of a hardcoded constant: it is what lets a truly game-agnostic part work in a genre that had its own names first.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search