From edc3545c02c85ecda714b91bc0d72c4bee0cadb8 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 20 Dec 2022 13:43:44 +0100 Subject: [PATCH] heal anim --- assets/Data/GameSettings.json | 4 ++-- assets/Scripts/Game/Unit/Player/Player.ts | 11 ++++++++--- .../Game/Unit/Player/PlayerUI/PlayerHealthUI.ts | 2 +- assets/Scripts/Game/Unit/UnitHealth.ts | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 103a6a8..1f6b965 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -146,7 +146,7 @@ "lifetime": -1, "xpReward": 1, "goldReward": 0, - "healthPotionRewardChance": 0.5 + "healthPotionRewardChance": 0.05 }, { "id": "StandardEnemy", @@ -496,6 +496,6 @@ ] }, "items": { - "healthPerPotion": 10 + "healthPerPotion": 5 } } \ No newline at end of file diff --git a/assets/Scripts/Game/Unit/Player/Player.ts b/assets/Scripts/Game/Unit/Player/Player.ts index df2b03f..750d9a9 100644 --- a/assets/Scripts/Game/Unit/Player/Player.ts +++ b/assets/Scripts/Game/Unit/Player/Player.ts @@ -34,7 +34,7 @@ export class Player extends Component { this.speed = data.speed; this.weapon.init(data.strikeDelay, data.damage); - this.health.HealthPointsChangeEvent.on(this.animateHurt, this); + this.health.HealthPointsChangeEvent.on(this.animateHpChange, this); this.playerUI.init(this.health); } @@ -94,8 +94,13 @@ export class Player extends Component { } } - private async animateHurt(): Promise { - this.sprite.color = Color.RED; + private async animateHpChange(hpChange: number): Promise { + if (hpChange < 0) { + this.sprite.color = Color.RED; + } else { + this.sprite.color = Color.GREEN; + } + await delay(100); this.sprite.color = Color.WHITE; } diff --git a/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerHealthUI.ts b/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerHealthUI.ts index 8d9bfa2..6134421 100644 --- a/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerHealthUI.ts +++ b/assets/Scripts/Game/Unit/Player/PlayerUI/PlayerHealthUI.ts @@ -1,5 +1,5 @@ import { Component, ProgressBar, _decorator } from "cc"; -import { UnitHealth } from "../UnitHealth"; +import { UnitHealth } from "../../UnitHealth"; const { ccclass, property } = _decorator; @ccclass("PlayerHealthUI") diff --git a/assets/Scripts/Game/Unit/UnitHealth.ts b/assets/Scripts/Game/Unit/UnitHealth.ts index 3791356..ee31eab 100644 --- a/assets/Scripts/Game/Unit/UnitHealth.ts +++ b/assets/Scripts/Game/Unit/UnitHealth.ts @@ -28,12 +28,12 @@ export class UnitHealth { public heal(points: number): void { this.healthPoints = Math.min(this.maxHealthPoints, this.healthPoints + points); - this.healthPointsChangeEvent.trigger(this.healthPoints); + this.healthPointsChangeEvent.trigger(points); } public damage(points: number): void { this.healthPoints -= points; - this.healthPointsChangeEvent.trigger(this.healthPoints); + this.healthPointsChangeEvent.trigger(-points); } public setMaxHealth(maxHealth: number): void {