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
+22 -7
View File
@@ -5,6 +5,7 @@
import Player from "../entities/Player";
import Bat from "../entities/Enemys/Bat";
import Item from "../entities/Item";
export default class Game extends Phaser.Scene {
@@ -145,16 +146,19 @@ export default class Game extends Phaser.Scene {
const spawnPoint = map.findObject("Objects", obj => obj.name === "player");
this.enemys = this.add.group();
this.items = this.add.group();
this.player = new Player(this, spawnPoint, 'char');
const batSpawns = map.objects[0].objects.filter(obj => obj.name === "bat");
batSpawns.forEach(s => {
map.objects[0].objects.filter(obj => obj.name === "bat").forEach(s => {
let bat = new Bat(this, s);
bat.fly(s.type === "" ? 90 : parseInt(s.type));
this.enemys.add(bat)
});
})
map.objects[0].objects.filter(obj => obj.name === "item").forEach(s => {
let item = new Item(this, s);
this.items.add(item)
})
this.worldLayer.setCollisionByProperty({collides: true});
@@ -192,7 +196,17 @@ export default class Game extends Phaser.Scene {
this.keyLeft = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
this.keyRight = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
this.keyDown = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
this.keyDie = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C);
// this.keyDie = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C);
this.keyPickup = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C);
this.keyAction1 = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
this.keyAction2 = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E);
this.physics.add.overlap(this.player, this.items, (p, i) => {
if (this.keyPickup.isDown && i.canPickup()) {
p.pickup(i);
this.keyPickup.reset();
}
})
}
update(time, delta) {
@@ -204,7 +218,8 @@ export default class Game extends Phaser.Scene {
}
dieActive() {
return this.keyDie.isDown;
return false;
// return this.keyDie.isDown;
}
rightActive() {