added a whole lot of crap

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-07-15 23:47:44 +02:00
parent 4edf8453d1
commit e3b9eff67d
25 changed files with 4490 additions and 59 deletions
+15 -3
View File
@@ -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