added zombie texture and basic ki

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-07-16 05:45:59 +02:00
parent f1d6c7d69f
commit 0004849110
12 changed files with 161 additions and 23 deletions
+10 -2
View File
@@ -17,19 +17,26 @@ export default class Entity extends Phaser.GameObjects.Sprite {
}
hit(dmg) {
if (dmg <= 0)
return;
if (this.hitCooldown)
return;
this.hitCooldown = true;
setTimeout(() => this.hitCooldown = false, 1000);
this.setData('hp', this.getData('hp') - dmg);
console.log(this, this.getData('hp'));
// play hit animation
const shouldDie = this.getData('hp') <= 0;
if (shouldDie) {
this.body.velocity.x = 0;
this.setData('active', false);
} else {
setTimeout(() => this.hitCooldown = false, 1000);
}
if (this.hitAnimation !== null) {
this.anims.stop();
this.play(this.hitAnimation)
@@ -44,6 +51,7 @@ export default class Entity extends Phaser.GameObjects.Sprite {
die() {
if (this.dieAnimation !== null && this.active) {
this.setData('active', false);
this.play(this.dieAnimation)
.once('animationcomplete', () => this.destroy());
} else