added item chests, audio and deployment
Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
+28
-8
@@ -6,6 +6,8 @@
|
||||
import Entity from "./Entity";
|
||||
import AttackA from "./Attacks/AttackA";
|
||||
import AttackB from "./Attacks/AttackB";
|
||||
import Item from "./Item";
|
||||
import Chest from "./Chest";
|
||||
|
||||
export default class Player extends Entity {
|
||||
|
||||
@@ -34,17 +36,34 @@ export default class Player extends Entity {
|
||||
this.hitAnimation = 'hit';
|
||||
}
|
||||
|
||||
pickup(item) {
|
||||
if (this.items.length >= 1) {
|
||||
this.items.shift().setPosition(this.x, this.y).drop();
|
||||
interact(item) {
|
||||
|
||||
if (item instanceof Item) {
|
||||
if (this.items.length >= 1) {
|
||||
this.items.shift().setPosition(this.x, this.y).drop();
|
||||
}
|
||||
|
||||
|
||||
item.interact();
|
||||
|
||||
this.items[0] = item;
|
||||
} else if (item instanceof Chest) {
|
||||
item.interact();
|
||||
}
|
||||
}
|
||||
|
||||
console.log(item);
|
||||
|
||||
item.pickup();
|
||||
|
||||
this.items[0] = item;
|
||||
hit(dmg) {
|
||||
super.hit(dmg);
|
||||
if (this.getData('hp') > this.scene.hearts.length)
|
||||
this.setData('hp', this.scene.hearts.length);
|
||||
|
||||
for (let i = this.getData('hp'); i < this.scene.hearts.length; i++) {
|
||||
this.scene.hearts[i].alpha = 0;
|
||||
}
|
||||
for (let i = 0; i < this.getData('hp'); i++) {
|
||||
this.scene.hearts[i].alpha = 1;
|
||||
}
|
||||
}
|
||||
|
||||
update(...args) {
|
||||
@@ -103,7 +122,7 @@ export default class Player extends Entity {
|
||||
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();
|
||||
this.items.shift().use(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +133,7 @@ export default class Player extends Entity {
|
||||
.once('animationcomplete', () => {
|
||||
this.setFrame(51);
|
||||
this.scene.scene.pause();
|
||||
this.scene.music.pause();
|
||||
this.scene.scene.launch('GUI', {key: 'Dead'}).bringToTop('GUI');
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user