Skip to content

Health

namespace Griff.Scenes;
public sealed class Health : Component

Hit 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.

public bool BlinkWhileInvincible { get; set; }

Blink the entity’s sprites while it can’t be hurt.

public float Current { get; set; }

Hit points now. Normally starts at Max.

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”.

public string? DeathSound { get; set; }

Plays when it dies, from where it is: an explosion, a last cry.

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.

public bool FlashOnHit { get; set; }

Flash the entity’s sprites white when hit.

public string? HurtSound { get; set; }

Plays when damage lands but doesn’t kill, from where it is. Make one with Audio > New Sound (Hit).

public float InvincibleTime { get; set; }

Seconds after a hit during which further damage is ignored. 0 lets every hit land.

public bool IsDead { get; }
public bool IsInvincible { get; }

True for InvincibleTime after a hit.

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.

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.

public float RespawnDelay { get; set; }

Seconds it stays gone before it comes back (see Respawn).

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.

public void Advance(float seconds)

Counts down invincibility. Called by the game.

public float CurrentDrawn(StepBlend blend)

Its Current hit points in a frame drawn as blend says, for a meter showing them.

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.

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)
public event Action<float, Entity>? Damaged

Raised when damage lands, with the amount and what dealt it (if known).

public event Action? Died

Raised once, when Current reaches zero.

public event Action? Respawned

Raised when it comes back after dying (see Respawn).