added zombie texture and basic ki
Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
+10
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user