Construct a HazardBehavior
Optionaldamage?: numberFlat 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) => booleanWhich actors can this hazard affect (default: only player-controlled actors)
OptionalimmuneToInvincibility?: booleanDoes invincibility defeat this hazard?
OptionalinstantDefeat?: booleanShould this hazard always defeat whatever it touches?
OptionalonContact?: (zone: DIRECTION) => numberDecide the outcome of a contact from a
given zone (default: always deal damage)
OptionalonDefeated?: (self: Actor, defeatedBy?: Actor<unknown>) => voidCode to run when this hazard is defeated
Optionalteam?: numberThe team this actor belongs to (default 0)
Protected Optional_The actor associated with this Behavior
Flat damage dealt for a contact that doesn't defeat this hazard (the
default onContact's outcome)
Which actors is this hazard even capable of hurting? Defaults to player-controlled actors only
When the other actor is invincible, does this hazard survive the contact anyway?
Does this hazard always defeat whatever it touches, regardless of geometry or invincibility?
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.
OptionalonCode to run when this hazard is defeated
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.
Static ReadonlyENEMIES_The stage.score.counters key for how many HazardBehaviors have ever been constructed
Static ReadonlyENEMIES_The stage.score.counters key for how many HazardBehaviors have been defeated
The actor associated with this Behavior
Indicate that this Behavior should ignore collisions with some other property
ProtecteddisableTurn off physical collisions for actor. Used by Behaviors that are only
ever passed through, not physically collided with, like coins.
The actor being attached (may be undefined, if this Behavior is being detached)
ProtectedrequireIf 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).
The actor being attached (may be undefined, if this Behavior is being detached)
The name to use in the warning message
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.
How much damage to apply
OptionaldealtBy: Actor<unknown>
The actor responsible for the damage, if any
HazardBehavior describes something to be avoided or defeated.
Every HazardBehavior increments the
HazardBehavior.ENEMIES_CREATEDcounter when constructed andHazardBehavior.ENEMIES_DEFEATEDwhen defeated, so a win condition like "defeat them all" is juststage.score.addWinCondition(() => stage.score.counters.get(HazardBehavior.ENEMIES_DEFEATED) >= stage.score.counters.get(HazardBehavior.ENEMIES_CREATED)).