ReadonlycountersThis level's counters (goodies, enemies, the stopwatch, or anything your own game code defines)
OptionalloseCode for building an overlay to announce that current level is lost
OptionalwinCode for building an overlay to announce that current level is won
Static ReadonlySTOPWATCHThe counter that tracks elapsed time in the current level, in seconds
Register a predicate that loses the level the first time it returns true
The predicate to check every clock tick
Register a predicate that wins the level the first time it returns true
The predicate to check every clock tick
When a playable level is lost, we run this code to shut it down and then
either show an overlay (loseSceneBuilder) or move straight to the next
stage via stage.switchTo(this.onLose). Does nothing if the level has
already been won or lost.
How to build the next level if the current level is lost
How to build the next level if the current level is won
Reset all the scores at the beginning of a new level
When a playable level is won, we run this code to shut it down and then
either show an overlay (winSceneBuilder) or move straight to the next
stage via stage.switchTo(this.onWin). Does nothing if the level has
already been won or lost.
ScoreService tracks a level's progress via a
Counterregistry, and decides when to win or lose the level via predicate functions that are registered withaddWinCondition/addLoseCondition.JetLag doesn't hardcode what "winning" means. Once per clock tick, ScoreService checks every registered predicate (win conditions first, then lose conditions) and acts on the first one that returns true. A predicate is usually just a check against
stage.score.counters, e.g.stage.score.addWinCondition(() => stage.score.counters.get("coins") >= 10).stage.score.countersentries fall into three different categories:ScoreService.STOPWATCH.HazardBehavior.ENEMIES_CREATED/ENEMIES_DEFEATED, not here.CollectableBehavior.onCollect,GoalBehavior.onArrivalare themselves the counter key) -- these aren't "well-known" at all, since nothing about them is fixed.