Health
Health gives an entity a pool of hit points, starting full. The hero is the entity with the Hero trait, which the Player component spawns.
Its props are in HealthProps.
dealDamage(entity, amount) takes an entity’s health down, never below zero, and the step reaps the entity at zero.
useHealth(entity) reads an entity’s { current, maximum } for a bar or a label. It returns undefined while the entity has no Health, so the caller chooses whether to hide the bar or draw it full.
Where it runs
Section titled “Where it runs”Server. Health has a consequence: it can end the entity.
import { Entity, Health, type EntityProps } from "@daniel-zarinski/engine";
export function Yeti({ position }: Pick<EntityProps, "position">) { return ( <Entity model="yeti" position={position}> <Health maximum={30} /> </Entity> );}