health(hp: number, maxHP?: number): HealthComp
Handles health related logic and events.
param
hp- The initial health points.
param
maxHP- The maximum health points.
const player = add([
health(3),
])
player.onCollide("bad", (bad) => {
player.hurt(1)
bad.hurt(1)
})
player.onCollide("apple", () => {
player.heal(1)
})
player.on("hurt", () => {
play("ouch")
})
// triggers when hp reaches 0
player.on("death", () => {
destroy(player)
go("lose")
})
returns
The health comp.
since
v2000.0
group
Components