Class HitPoints

java.lang.Object
com.codename1.gaming.platformer.HitPoints

public final class HitPoints extends Object

Hit points, invulnerability frames and knock-back for a Actor.

PlatformWorld#damage is the one way to hurt something: it checks the invulnerability window, knocks the actor away from the source, locks its control briefly and, at zero, hands it to PlatformWorld#onDeath.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Ticks of invulnerability after a hit.
    int
    Horizontal knock-back speed, fixed point per tick.
    int
    Upward knock-back speed, fixed point per tick.
    int
    Hit points when full.
    int
    Ticks control is locked after a hit.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HitPoints(int max)
    Creates a full health pool.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Current hit points.
    int
    Ticks of invulnerability left, which a view flickers the sprite by.
    void
    Makes the owner invulnerable for a while, as a power-up or respawn does.
    void
    heal(int amount)
    Restores hit points, up to the maximum.
    boolean
    Whether hits are currently ignored.
    void
    Refills and clears invulnerability, on respawn.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • max

      public int max
      Hit points when full.
    • invulnerableTicks

      public int invulnerableTicks
      Ticks of invulnerability after a hit.
    • knockbackX

      public int knockbackX
      Horizontal knock-back speed, fixed point per tick.
    • knockbackY

      public int knockbackY
      Upward knock-back speed, fixed point per tick.
    • stunTicks

      public int stunTicks
      Ticks control is locked after a hit.
  • Constructor Details

    • HitPoints

      public HitPoints(int max)

      Creates a full health pool.

      Parameters
      • max: hit points
  • Method Details

    • getCurrent

      public int getCurrent()

      Current hit points.

      Returns

      the hit points

    • isInvulnerable

      public boolean isInvulnerable()

      Whether hits are currently ignored.

      Returns

      true during invulnerability

    • getInvulnerableRemaining

      public int getInvulnerableRemaining()

      Ticks of invulnerability left, which a view flickers the sprite by.

      Returns

      the remaining ticks

    • heal

      public void heal(int amount)

      Restores hit points, up to the maximum.

      Parameters
      • amount: hit points to add
    • reset

      public void reset()
      Refills and clears invulnerability, on respawn.
    • grantInvulnerability

      public void grantInvulnerability(int ticks)

      Makes the owner invulnerable for a while, as a power-up or respawn does.

      Parameters
      • ticks: how long