jetlag2d
    Preparing search index...

    Class HazardBehavior

    HazardBehavior describes something to be avoided or defeated.

    Every HazardBehavior increments the HazardBehavior.ENEMIES_CREATED counter when constructed and HazardBehavior.ENEMIES_DEFEATED when defeated, so a win condition like "defeat them all" is just stage.score.addWinCondition(() => stage.score.counters.get(HazardBehavior.ENEMIES_DEFEATED) >= stage.score.counters.get(HazardBehavior.ENEMIES_CREATED)).

    Hierarchy (View Summary)

    Index
    • Construct a HazardBehavior

      Parameters

      • cfg: {
            damage?: number;
            eligible?: (other: Actor) => boolean;
            immuneToInvincibility?: boolean;
            instantDefeat?: boolean;
            onContact?: (zone: DIRECTION) => number;
            onDefeated?: (self: Actor, defeatedBy?: Actor<unknown>) => void;
            team?: number;
        } = {}
        • Optionaldamage?: number

          Flat damage dealt for a contact that doesn't defeat this hazard (default 2, so that a hazard with no onContact configured defeats a default-strength actor without itself disappearing -- matching the old Enemy default)

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

          Which actors can this hazard affect (default: only player-controlled actors)

        • OptionalimmuneToInvincibility?: boolean

          Does invincibility defeat this hazard?

        • OptionalinstantDefeat?: boolean

          Should this hazard always defeat whatever it touches?

        • OptionalonContact?: (zone: DIRECTION) => number

          Decide the outcome of a contact from a given zone (default: always deal damage)

        • OptionalonDefeated?: (self: Actor, defeatedBy?: Actor<unknown>) => void

          Code to run when this hazard is defeated

        • Optionalteam?: number

          The team this actor belongs to (default 0)

      Returns HazardBehavior

    _actor?: Actor<unknown>

    The actor associated with this Behavior

    damage: number

    Flat damage dealt for a contact that doesn't defeat this hazard (the default onContact's outcome)

    eligible: (other: Actor) => boolean

    Which actors is this hazard even capable of hurting? Defaults to player-controlled actors only

    immuneToInvincibility: boolean

    When the other actor is invincible, does this hazard survive the contact anyway?

    instantDefeat: boolean

    Does this hazard always defeat whatever it touches, regardless of geometry or invincibility?

    onContact: (zone: DIRECTION) => number

    Decide the outcome of a contact, given which zone it came from (see relativeZone). Negative defeats this actor, positive damages the other actor by that amount, zero does nothing.

    onDefeated?: (self: Actor, defeatedBy?: Actor<unknown>) => void

    Code to run when this hazard is defeated

    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.

    ENEMIES_CREATED: "enemiesCreated"

    The stage.score.counters key for how many HazardBehaviors have ever been constructed

    ENEMIES_DEFEATED: "enemiesDefeated"

    The stage.score.counters key for how many HazardBehaviors have been defeated

    • 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

    • This hazard takes amount damage (e.g. from a ThrowableBehavior). If its actor has a HealthBehavior, this is just health.damage(...) -- otherwise, this hazard has no hit points of its own, so any amount of damage defeats it outright.

      Parameters

      • amount: number

        How much damage to apply

      • OptionaldealtBy: Actor<unknown>

        The actor responsible for the damage, if any

      Returns void