heal anim

This commit is contained in:
Martin 2022-12-20 13:43:44 +01:00
parent dbb55957a0
commit edc3545c02
4 changed files with 13 additions and 8 deletions

View File

@ -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
}
}

View File

@ -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<void> {
this.sprite.color = Color.RED;
private async animateHpChange(hpChange: number): Promise<void> {
if (hpChange < 0) {
this.sprite.color = Color.RED;
} else {
this.sprite.color = Color.GREEN;
}
await delay(100);
this.sprite.color = Color.WHITE;
}

View File

@ -1,5 +1,5 @@
import { Component, ProgressBar, _decorator } from "cc";
import { UnitHealth } from "../UnitHealth";
import { UnitHealth } from "../../UnitHealth";
const { ccclass, property } = _decorator;
@ccclass("PlayerHealthUI")

View File

@ -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 {