logo
By Lawrence

4 minutes

Tally the Kills

The mission knows you need six kills. It will not tell you what a kill is worth, because to a mission every kill is worth exactly one sixth of a win. A score answers a different question: which run was better. It wants its own bucket.

        "SpaceShooterScore": {}

Names match, so the loader wires the System. Defaults are score: 0 and pointsPerKill: 100.

The whole component

src/components/SpaceShooterScore/SpaceShooterScore.defs.ts
/** The single-player run score. One per scene, on the world/director entity. */
export class SpaceShooterScoreComponent extends Component {
  score: number;
  pointsPerKill: number;

  constructor(data: Partial<SpaceShooterScoreInput> = {}) {
    super();
    const p = { ...DEFAULT_SPACE_SHOOTER_SCORE_PARAMS, ...data };
    this.score = p.score;
    this.pointsPerKill = p.pointsPerKill;
  }

  serialize(): SpaceShooterScoreInput {
    return {
      score: this.score,
      pointsPerKill: this.pointsPerKill,
    };
  }
}

A number you add to and a number you multiply by. There is no list of kills, no per-enemy breakdown, no combo timer. A scoreboard that renders one integer needs one integer.

The name is doing a job. There is already a Score component in the library, the generic per-player one that listens for score.add and goal.scored. This one counts ship kills. Every component in the marketplace shares one flat namespace, so a variant is named for the subgenre it belongs to rather than stealing the bare name from the general case.

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