added items and pickup basic
Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
+22
-7
@@ -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() {
|
||||
|
||||
@@ -12,6 +12,9 @@ import charD from "../assets/char_d/spritesheet.png";
|
||||
import tiles from "../assets/tileset.png";
|
||||
import batFly from "../assets/BatFly.png";
|
||||
import batDie from "../assets/BatDie.png";
|
||||
import item_01 from "../assets/items/itemshard_01.png";
|
||||
import item_02 from "../assets/items/itemshard_02.png";
|
||||
import item_03 from "../assets/items/itemshard_03.png";
|
||||
|
||||
export default class Preload extends Phaser.Scene {
|
||||
|
||||
@@ -22,6 +25,9 @@ export default class Preload extends Phaser.Scene {
|
||||
preload() {
|
||||
this.loadingScreen();
|
||||
this.load.image("logo", logoImg);
|
||||
this.load.image("item_01", item_01);
|
||||
this.load.image("item_02", item_02);
|
||||
this.load.image("item_03", item_03);
|
||||
this.load.spritesheet('charA', charA, {frameWidth: 79, frameHeight: 63/*, margin: 1, spacing: 2*/});
|
||||
this.load.spritesheet('charB', charB, {frameWidth: 79, frameHeight: 63/*, margin: 1, spacing: 2*/});
|
||||
this.load.spritesheet('charC', charC, {frameWidth: 79, frameHeight: 63/*, margin: 1, spacing: 2*/});
|
||||
|
||||
Reference in New Issue
Block a user