# rmp::behavior::Health

> Hit points, a window of invulnerability with a blink, and death.

Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html

behavior `#include <rmp/behavior.h>` [include/rmp/behavior.h:478](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L478-L530)

struct 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 `{ .hp = 5 }` needs no second number |
| `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 `damage()` takes hp to 0 |
| `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 `if` at the top of every _collision. `player.add<rmp::behavior::Health>({ .hp = 3, .hurt_by = layer::ENEMY });` It is the OTHER object's `collision_layer` that is tested, the same numbers [`rmp::Object::collision_mask`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_mask) uses — so a spike, an enemy and a bullet are one layer each and a player is hurt by whichever it names. The invulnerable window applies, which is what stops standing inside a fire costing sixty hearts a second. |
| `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 `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. |

### `damage`, `heal`

bool damage(Object &self, int amount = 1)

void heal(int amount = 1)

function [include/rmp/behavior.h:505](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L505)

Returns whether it landed. Damage during the invulnerable window does not, which is what stops one spike costing three hearts in three frames.

### `invulnerable`

bool invulnerable() const

function [include/rmp/behavior.h:510](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L510)

Whether the window after a hit is still open, during which `damage()` lands nothing.

### `dead`

bool dead() const

function [include/rmp/behavior.h:513](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L513)

Whether hp is 0 or less. A death through `damage()` is final: `heal()` does nothing after it.
