jetlag2d
    Preparing search index...

    Class ScoreService

    ScoreService tracks a level's progress via a Counter registry, and decides when to win or lose the level via predicate functions that are registered with addWinCondition/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.counters entries fall into three different categories:

    • The one counter ScoreService itself owns: ScoreService.STOPWATCH.
    • Well-known counters that a Behavior updates automatically. These are documented as public static strings on the Behavior that owns them, e.g. HazardBehavior.ENEMIES_CREATED/ENEMIES_DEFEATED, not here.
    • Arbitrary counter keys that a game author chooses when configuring a Behavior (e.g. CollectableBehavior.onCollect, GoalBehavior.onArrival are themselves the counter key) -- these aren't "well-known" at all, since nothing about them is fixed.
    Index
    counters: Counter = ...

    This level's counters (goodies, enemies, the stopwatch, or anything your own game code defines)

    loseSceneBuilder?: (overlay: Scene, screenshot: ImageSprite) => void

    Code for building an overlay to announce that current level is lost

    winSceneBuilder?: (overlay: Scene, screenshot: ImageSprite) => void

    Code for building an overlay to announce that current level is won

    STOPWATCH: "stopwatch"

    The counter that tracks elapsed time in the current level, in seconds

    • Register a predicate that loses the level the first time it returns true

      Parameters

      • condition: () => boolean

        The predicate to check every clock tick

      Returns void

    • Register a predicate that wins the level the first time it returns true

      Parameters

      • condition: () => boolean

        The predicate to check every clock tick

      Returns void

    • 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.

      Returns void

    • 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.

      Returns void