5 minutes
Right now you can clear wave after wave and nothing changes. No number goes up when an enemy falls. An enemy that walks up to your ship just stops and waits. There are no stakes yet. You shoot targets, but nothing is on the line. Two small changes will turn this into a real game. First, you add a reason to keep shooting. Second, you add a cost for letting enemies get close.
The scoreboard and points per kill
The game keeps score on one new entity. Add it to the running scene:
That one Score component on one entity is the only scene change in this lesson. defaultPoints: 100 is the score you give when no one names a value. scores: { Player: 0 } starts the player's total at zero. Nothing else in the scene names ScoreState. The Score system finds it on its own. It treats that entity as the one scoreboard as soon as the world loads.
The scorekeeping is plain math. No 3D shows up in it at all:
addScore takes an owner id and an optional point value. It reads the current total, adds the points, and returns a record of the before and after:
delta is the change this one call made. It is not the running total. So a HUD can flash "+100" without doing any math. If you pass no points, it uses the component's defaultPoints instead. But a kill always names its own value. That value comes from the enemy.
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.