+15
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Pascal Syma <pascal@syma.dev>
|
||||
* Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
@@ -16,10 +16,22 @@ export default class Entity extends Phaser.GameObjects.Sprite {
|
||||
this.dieAnimation = null;
|
||||
}
|
||||
|
||||
hit() {
|
||||
hit(dmg) {
|
||||
|
||||
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 (this.hitAnimation !== null) {
|
||||
this.anims.stop();
|
||||
this.play(this.hitAnimation)
|
||||
.once('animationcomplete', () => {
|
||||
if (shouldDie) this.die()
|
||||
@@ -31,7 +43,7 @@ export default class Entity extends Phaser.GameObjects.Sprite {
|
||||
}
|
||||
|
||||
die() {
|
||||
if (this.dieAnimation !== null) {
|
||||
if (this.dieAnimation !== null && this.active) {
|
||||
this.play(this.dieAnimation)
|
||||
.once('animationcomplete', () => this.destroy());
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user