added items and pickup basic

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-05-31 11:08:56 +02:00
parent a726db1306
commit 7c4d08cf8f
9 changed files with 142 additions and 17 deletions
+24 -3
View File
@@ -24,13 +24,28 @@ export default class Player extends Entity {
this.attackHitbox = this.scene.add.group([
this.attackA
]);
this.items = [];
}
pickup(item) {
if (this.items.length >= 1) {
this.items.shift().setPosition(this.x, this.y).drop();
}
console.log(item);
item.pickup();
this.items[0] = item;
}
update(...args) {
if (this.scene.dieActive()) {
this.pause = true;
this.play('die', true)
.on('animationcomplete', () => {
.once('animationcomplete', () => {
this.setFrame(51);
this.scene.scene.pause();
})
@@ -63,11 +78,11 @@ export default class Player extends Entity {
this.body.setOffset(4, 16);
}
this.setData('speed', 100);
// this.setData('speed', 100);
// animation
if (this.anims.getCurrentKey().startsWith('attack_')) {
this.setData('speed', 50);
// this.setData('speed', 50);
} else if (this.scene.keySpace.isDown) {
// const nextAttack = [this.attackA].sort(() => 0.5 - Math.random())[0];
// nextAttack.start();
@@ -86,5 +101,11 @@ export default class Player extends Entity {
this.attackHitbox.getChildren().forEach(c => {
c.update()
});
this.items.forEach(i => i.setPosition(this.body.x, this.body.y - 16));
if (this.scene.keyAction1.isDown && this.items.length >= 1) {
this.items.shift().die();
}
}
}