jetlag2d
    Preparing search index...

    Class ThrowableBehavior

    ThrowableBehavior is for actors that can be tossed from another actor's location, in order to damage hazards.

    Hierarchy (View Summary)

    Index
    • Construct a ThrowableBehavior

      Parameters

      • cfg: {
            damage?: number;
            disappearOnCollide?: boolean;
            reclaimer?: (actor: Actor) => void;
            team?: number;
        } = {}
        • Optionaldamage?: number

          How much damage should this do? (default 1)

        • OptionaldisappearOnCollide?: boolean

          Should this disappear when it collides with another throwable? (default true)

        • Optionalreclaimer?: (actor: Actor) => void

          Code to run when this is reclaimed due to a collision

        • Optionalteam?: number

          The team this actor belongs to (default 0)

      Returns ThrowableBehavior

    _actor?: Actor<unknown>

    The actor associated with this Behavior

    damage: number

    How much damage does this throwable do?

    disappearOnCollide: boolean

    When throwables collide, and they are not sensors, one will disappear. We can keep both on screen by setting this false

    rangeFrom: JLPoint = ...

    This is the initial point from which the throwable was tossed

    reclaimer?: (actor: Actor) => void

    Code to run when this throwable is reclaimed due to a collision

    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.

    • get actor(): Actor<unknown> | undefined

      The actor associated with this Behavior

      Returns Actor<unknown> | undefined

    • set actor(actor: Actor<unknown> | undefined): void

      Attaching this behavior upgrades a non-dynamic body to dynamic, and marks it as a "bullet" (Box2D's continuous collision detection) so a fast-moving throwable can't tunnel through a thin wall between physics steps. ProjectileMovement already does this too, but a throwable shouldn't depend on also having a ProjectileMovement to get it.

      Parameters

      • actor: Actor<unknown> | undefined

      Returns void

    • 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

    • Toss in the direction of a specified point.

      Parameters

      • cfg: {
            actor: Actor;
            fixedVectorVelocity?: number;
            from: { x: number; y: number };
            multiplier?: number;
            offset: JLOffset;
            rotateVectorToss?: boolean;
            to: { x: number; y: number };
        }
        • actor: Actor

          The actor who is performing the toss

        • OptionalfixedVectorVelocity?: number

          A fixed velocity, regardless of distance

        • from: { x: number; y: number }

          The center of the actor doing the toss

        • Optionalmultiplier?: number

          A multiplier on speed

        • offset: JLOffset

          The distance between the center of the throwable and the center of the actor tossing it

        • OptionalrotateVectorToss?: boolean

          Should this be rotated to face the direction it's tossed?

        • to: { x: number; y: number }

          The point at which to toss

      Returns void

    • Toss in a single, predetermined direction

      Parameters

      • cfg: { actor: Actor; offset: JLOffset; velocity: { x: number; y: number } }
        • actor: Actor

          The actor who is performing the toss

        • offset: JLOffset

          The distance between the center of the throwable and the center of the actor tossing it

        • velocity: { x: number; y: number }

          The velocity of the throwable when it is tossed

      Returns void