Class Ability

java.lang.Object
com.codename1.gaming.platformer.Ability
Direct Known Subclasses:
CrouchAbility, DashAbility, FlyAbility, GlideAbility, GripAbility, JetpackAbility, JumpAbility, LadderAbility, LookAbility, MoveAbility, SwimAbility, WallJumpAbility, WeaponAbility

public abstract class Ability extends Object

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Runs before any ability sets velocity: timers and input edges.
    long
    hashState(long h)
    Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught.
    boolean
    Whether the ability runs.
    void
    Runs after the body moved, with the new contacts.
    protected static long
    mix(long h, long v)
    FNV-1a step used by hashState implementations.
    abstract void
    Sets velocity and claims a MovementState.
    void
    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.
    void
    setEnabled(boolean enabled)
    Enables or disables the ability.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public void earlyProcess(Actor c, PlatformWorld world)

      Runs before any ability sets velocity: timers and input edges.

      Parameters
      • c: the actor
      • world: the world
    • process

      public abstract void process(Actor c, PlatformWorld world)

      Sets velocity and claims a MovementState.

      Parameters
      • c: the actor
      • world: 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

      public void lateProcess(Actor c, PlatformWorld world)

      Runs after the body moved, with the new contacts.

      Parameters
      • c: the actor
      • world: 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 hashState implementations.

      Parameters
      • h: the running hash
      • v: the value to mix in
      Returns

      the updated hash