mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 03:38:58 +00:00
heal anim
This commit is contained in:
parent
dbb55957a0
commit
edc3545c02
@ -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
|
||||
}
|
||||
}
|
@ -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> {
|
||||
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;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Component, ProgressBar, _decorator } from "cc";
|
||||
import { UnitHealth } from "../UnitHealth";
|
||||
import { UnitHealth } from "../../UnitHealth";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PlayerHealthUI")
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user