Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class HitPoints

  1. Object
  2. HitPoints

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.

Fields

public int maxHit points when full.
public int invulnerableTicksTicks of invulnerability after a hit.
public int knockbackXHorizontal knock-back speed, fixed point per tick.
public int knockbackYUpward knock-back speed, fixed point per tick.
public int stunTicksTicks control is locked after a hit.

Constructors

public HitPoints(int max)Creates a full health pool.

Methods

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

Inherited methods

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 int
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 int
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 int
how long