added items and pickup basic
Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
+24
-3
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user