Health
namespace Griff.Scenes;
public sealed class Health : ComponentHit points. Scripts call Damage (or a DamageOnTouch does it with no code); after a hit the entity can’t be hurt again for InvincibleTime, flashing and blinking to show it. At zero it dies: its behaviors hear OnDeath, the DeathMessage is sent, and it’s destroyed.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”BlinkWhileInvincible
Section titled “BlinkWhileInvincible”public bool BlinkWhileInvincible { get; set; }Blink the entity’s sprites while it can’t be hurt.
Current
Section titled “Current”public float Current { get; set; }Hit points now. Normally starts at Max.
DeathMessage
Section titled “DeathMessage”public string? DeathMessage { get; set; }A message sent with Game.Send when it dies, with the entity as its data, e.g. “PlayerDied” or “EnemyDied”.
DeathSound
Section titled “DeathSound”public string? DeathSound { get; set; }Plays when it dies, from where it is: an explosion, a last cry.
DestroyOnDeath
Section titled “DestroyOnDeath”public bool DestroyOnDeath { get; set; }Destroy the entity when it dies. Turn off to play a death animation first, and destroy it from a script.
FlashOnHit
Section titled “FlashOnHit”public bool FlashOnHit { get; set; }Flash the entity’s sprites white when hit.
HurtSound
Section titled “HurtSound”public string? HurtSound { get; set; }Plays when damage lands but doesn’t kill, from where it is. Make one with Audio > New Sound (Hit).
InvincibleTime
Section titled “InvincibleTime”public float InvincibleTime { get; set; }Seconds after a hit during which further damage is ignored. 0 lets every hit land.
IsDead
Section titled “IsDead”public bool IsDead { get; }IsInvincible
Section titled “IsInvincible”public bool IsInvincible { get; }True for InvincibleTime after a hit.
Loaded
Section titled “Loaded”public bool Loaded { get; set; }Set by the game once it has taken its hit points from the save data, so a rewind doesn’t do it again. Leave it be.
public float Max { get; set; }Most hit points it can have. Changing it while at full health keeps it at full health.
Respawn
Section titled “Respawn”public bool Respawn { get; set; }Come back after dying instead of being destroyed: hidden for RespawnDelay, then back at full health at the active Checkpoint (or where it started), briefly invincible. For the player in a platformer.
RespawnDelay
Section titled “RespawnDelay”public float RespawnDelay { get; set; }Seconds it stays gone before it comes back (see Respawn).
SaveAs
Section titled “SaveAs”public string? SaveAs { get; set; }Keeps its hit points (and its Max) in the game’s save data under this name, e.g. “Hearts”, so a health saved as the same name in the next scene starts with them (the player walking into the next level hurt) and so does the next run. Saved at zero (it died) it starts full. Empty keeps nothing.
Methods
Section titled “Methods”Advance
Section titled “Advance”public void Advance(float seconds)Counts down invincibility. Called by the game.
CurrentDrawn
Section titled “CurrentDrawn”public float CurrentDrawn(StepBlend blend)Its Current hit points in a frame drawn as blend says, for a meter showing them.
Damage
Section titled “Damage”public bool Damage(float amount, Entity? source = null)Takes amount hit points away, unless it’s already dead or still invincible from the last hit. Returns whether the damage landed. source is passed on to OnDamage.
Damage
Section titled “Damage”public bool Damage(float amount, Entity? source, bool always)As Damage; with always, it lands even while it can’t be hurt after the last hit: a blow that isn’t a touch, such as a card’s damage, each of which counts.
public float Heal(float amount)Gives back up to amount hit points, never past Max. Returns how many it got.
public void Kill()Dies straight away, invincible or not: falling out of the world, a reset button.
public static Health? Of(Entity entity)The health that counts for entity: its own, or its nearest ancestor’s (a hitbox child’s owner).
public override bool Uses(string property)Events
Section titled “Events”Damaged
Section titled “Damaged”public event Action<float, Entity>? DamagedRaised when damage lands, with the amount and what dealt it (if known).
public event Action? DiedRaised once, when Current reaches zero.
Respawned
Section titled “Respawned”public event Action? RespawnedRaised when it comes back after dying (see Respawn).