jetlag2d
    Preparing search index...

    Class GoalBehavior

    GoalBehavior is most easily thought of in the context of a maze game: an eligible actor that arrives (and, for the common case, just increments a named score counter -- e.g. stage.score.addWinCondition(() => stage.score.counters.get("destinationArrivals") >= 1)) or runs custom logic to decide whether to accept the arrival.

    Hierarchy (View Summary)

    Index
    • Construct a GoalBehavior

      Parameters

      • cfg: {
            capacity?: number;
            eligible?: (other: Actor) => boolean;
            onArrival: string | ((h: Actor) => boolean);
            team?: number;
        }
        • Optionalcapacity?: number

          How many actors this Goal can hold (default 1)

        • Optionaleligible?: (other: Actor) => boolean

          Which actors can arrive here (default: only player-controlled actors)

        • onArrival: string | ((h: Actor) => boolean)

          Decide whether to accept an arriving actor, or the name of a score counter to increment by one on every accepted arrival

        • Optionalteam?: number

          The team this actor belongs to (default 0)

      Returns GoalBehavior

    _actor?: Actor<unknown>

    The actor associated with this Behavior

    eligible: (other: Actor) => boolean

    Which actors are allowed to arrive here? Defaults to player-controlled actors only.

    onArrival: string | ((h: Actor) => boolean)

    Decide whether to accept an arriving actor, or the name of a score counter to increment by one on every accepted arrival. As a function, return true to accept the arrival (removing the arriving actor) or false to reject it (leaving both actors as they are). Note that the function doesn't auto-increment a counter.

    team: number = 0

    Which "team" this Behavior belongs to. A team is just a number, and for the most part it's only when user code consults teams that teams have meaning. The only exception is that HazardBehavior uses team to prevent team attack damage.

    • Turn off physical collisions for actor. Used by Behaviors that are only ever passed through, not physically collided with, like coins.

      Parameters

      • actor: Actor<unknown> | undefined

        The actor being attached (may be undefined, if this Behavior is being detached)

      Returns void

    • If actor's body isn't dynamic, warn and upgrade it to dynamic. Used by every Behavior whose whole point requires a dynamic body (e.g. setVelocity/forces actually doing something).

      Parameters

      • actor: Actor<unknown> | undefined

        The actor being attached (may be undefined, if this Behavior is being detached)

      • behaviorName: string

        The name to use in the warning message

      Returns void