alive
Permet à un objet de pouvoir recevoir des dégats
require
health()body()triggers on self
"dead""low health"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
invicibilityDelay | number | 0.2 | |
deathDelay | number | 0.4 |
example
alive({ invicibilityDelay: 0.2, deathDelay: 0.4}),function alive(p) { const param = { invicibilityDelay: 0.2, deathDelay: 0.4, ...p, }; return { id: 'alive', isAlive: true, shown: true, startHealth: null, invSavedTime: null, disapeared: false, require: ['health', 'body'], respawnPos: null, camera: null, add() { const invincible = () => { return time() - this.invSavedTime < param.invicibilityDelay; }; requestAnimationFrame(() => { this.startHealth = this.hp; for (const e of get('camera', { recursive: true })) { this.camera = e; } }); this.on('death', () => { if (this.isAlive) { wait(param.deathDelay, () => { this.trigger('dead'); this.hidden = true; this.collisionIgnore = ['*']; this.isStatic = true; }); } this.isAlive = false; }); this.on('respawn', () => { this.isAlive = true; this.hp = this.startHealth; }); this.on('hit', (d) => { if (!invincible() && this.isAlive && d > 0) { this.hp -= d; this.invSavedTime = time(); if (this.hp <= 1) this.trigger('low health'); } }); }, };}