added entitys, enemys, bats and custom attack hitboxes for players

added map loading and one-way collision (needs to move to tiled attribute tho)

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-05-20 11:13:21 +02:00
parent 4a22dbe657
commit a726db1306
22 changed files with 2166 additions and 30 deletions
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2020. Pascal Syma <pascal@syma.dev>
* All rights reserved.
*/
export default class Entity extends Phaser.GameObjects.Sprite {
constructor(scene, x, y, key) {
super(scene, x, y, key);
this.setData('hp', 1);
this.setData('dmg', 0);
this.scene = scene;
this.scene.add.existing(this);
this.scene.physics.world.enableBody(this, 0);
this.hitAnimation = null;
this.dieAnimation = null;
}
hit() {
// play hit animation
const shouldDie = this.getData('hp') <= 0;
if (this.hitAnimation !== null) {
this.play(this.hitAnimation)
.once('animationcomplete', () => {
if (shouldDie) this.die()
});
} else {
if (shouldDie)
this.die();
}
}
die() {
if (this.dieAnimation !== null) {
this.play(this.dieAnimation)
.once('animationcomplete', () => this.destroy());
} else
this.destroy();
}
update(...args) {
super.update(...args);
}
}