Class HitPoints
java.lang.Object
com.codename1.gaming.platformer.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionintTicks of invulnerability after a hit.intHorizontal knock-back speed, fixed point per tick.intUpward knock-back speed, fixed point per tick.intHit points when full.intTicks control is locked after a hit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCurrent hit points.intTicks of invulnerability left, which a view flickers the sprite by.voidgrantInvulnerability(int ticks) Makes the owner invulnerable for a while, as a power-up or respawn does.voidheal(int amount) Restores hit points, up to the maximum.booleanWhether hits are currently ignored.voidreset()Refills and clears invulnerability, on respawn.
-
Field Details
-
max
public int maxHit points when full. -
invulnerableTicks
public int invulnerableTicksTicks of invulnerability after a hit. -
knockbackX
public int knockbackXHorizontal knock-back speed, fixed point per tick. -
knockbackY
public int knockbackYUpward knock-back speed, fixed point per tick. -
stunTicks
public int stunTicksTicks 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
-