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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user