Class Ability
- Direct Known Subclasses:
CrouchAbility, DashAbility, FlyAbility, GlideAbility, GripAbility, JetpackAbility, JumpAbility, LadderAbility, LookAbility, MoveAbility, SwimAbility, WallJumpAbility, WeaponAbility
One thing a Actor can do -- walk, jump, dash, climb -- as a small,
separately tunable unit, in the manner of Corgi Engine's character abilities.
An actor runs its abilities in the order they were added, three times a tick:
earlyProcess before anything moves, process to set velocity and state, and
lateProcess after the body has moved and its contacts are known. Order matters
where two abilities read the same button: an ability that consumes the jump
press (a wall jump, a ladder jump) belongs before JumpAbility.
Abilities must be deterministic: they read only the actor, the world and
the tick's input, use Fx arithmetic and the world's Rng, and keep their
state in fields so Actor#hash can fold it in through hashState.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidearlyProcess(Actor c, PlatformWorld world) Runs before any ability sets velocity: timers and input edges.longhashState(long h) Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught.booleanWhether the ability runs.voidlateProcess(Actor c, PlatformWorld world) Runs after the body moved, with the new contacts.protected static longmix(long h, long v) FNV-1a step used byhashStateimplementations.abstract voidprocess(Actor c, PlatformWorld world) Sets velocity and claims aMovementState.voidreset()Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death.voidsetEnabled(boolean enabled) Enables or disables the ability.
-
Constructor Details
-
Ability
public Ability()
-
-
Method Details
-
isEnabled
public boolean isEnabled()Whether the ability runs. A disabled ability is skipped, which is how a power-up grants it mid-level.
Returns
true when enabled
-
setEnabled
public void setEnabled(boolean enabled) Enables or disables the ability.
Parameters
enabled: true to run it
-
earlyProcess
Runs before any ability sets velocity: timers and input edges.
Parameters
c: the actorworld: the world
-
process
Sets velocity and claims a
MovementState.Parameters
c: the actorworld: the world
-
reset
public void reset()Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death. The default does nothing; an ability with per-run state overrides it. -
lateProcess
Runs after the body moved, with the new contacts.
Parameters
c: the actorworld: the world
-
hashState
public long hashState(long h) Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught. The default mixes nothing.
Parameters
h: the running hash
Returns
the updated hash
-
mix
protected static long mix(long h, long v) FNV-1a step used by
hashStateimplementations.Parameters
h: the running hashv: the value to mix in
Returns
the updated hash
-