alive
Permet à un objet de pouvoir recevoir des dégats
require
health()body()parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
invicibilityDelay | number | 0.2 | |
flipY | boolean | true | |
hurtColor | object | { r: 0, g: 160, b: 160 } |
example
alive({ invicibilityDelay: 0.2, flipY: true, hurtColor: { r: 0, g: 160, b: 160 }}),function alive(p) { const param = { invicibilityDelay: 0.2, flipY: true, hurtColor: { r: 0, g: 160, b: 160 }, ...p } return { id: "alive", isAlive: true, shown: true, startHealth: null, invSavedTime: null, disapeared: false, require: ["health", "body"], respawnPos: null, invinsibile: false, camera: null, add() { requestAnimationFrame(() => { this.startHealth = this.hp() for (const e of get("camera", { recursive: true })) this.camera = e }) this.on("death", () => { this.isAlive = false if (param.flipY) this.flipY = true }) this.on("respawn", () => { this.isAlive = true this.flipY = false this.heal(this.startHealth - this.hp()) this.camera.updateCameraTargets() }) this.on("hit", (d) => { if (!this.invincible && this.isAlive) { this.hurt(d) this.invSavedTime = time() } }) }, update() { this.invinsibile = (this.invSavedTime == null || time() - this.invSavedTime < param.invicibilityDelay) }, }}