rmp::behavior::Health
Hit points, a window of invulnerability with a blink, and death.
Added to an object with add<rmp::behavior::Health>(); the framework calls its _ready, _update, _collision, _end with the object it is on.
Fields
| Field | Type | Default | What it is |
|---|---|---|---|
hp | int | 3 | Hit points left, and the number it starts with |
max_hp | int | 0 | 0 = whatever hp starts at, so |
invulnerable_for | float | 0.6f | 0 = no window |
blink_hz | float | 12 | Blinks per second while invulnerable; 0 = no blink |
destroy_on_death | bool | true | Destroy the object when it dies, after on_death |
on_death | Callback<Object &> | Once, when | |
on_damage | Callback<Object &, int> | The amount that actually landed | |
hurt_by | unsigned | 0 | WHICH LAYERS HURT. 0, the default, is "nothing does": contact costs nothing until a game says which contact costs something, and then it says it once here instead of writing the same It is the OTHER object's |
damage_on_hit | int | 1 | What one touch costs |
ours | struct { … } | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then |
damage, heal
Returns whether it landed. Damage during the invulnerable window does not, which is what stops one spike costing three hearts in three frames.
invulnerable
Whether the window after a hit is still open, during which damage() lands nothing.
dead
Whether hp is 0 or less. A death through damage() is final: heal() does nothing after it.