[fix]: Fixed level switching bug.

This commit is contained in:
corner 2020-04-11 17:48:51 +02:00
parent 0b07ff3f2a
commit 68d2f862d5
2 changed files with 7 additions and 5 deletions

View File

@ -64,8 +64,7 @@ class Portal extends TileSprite {
const element = this.player.items.keys[index];
if (element == this.key) {
this.action();
this.player.items.key = false;
delete this.player.items.keys[index];
break;
} else {
// Not the correct key
console.log("correct keyn't");

View File

@ -20,7 +20,7 @@ var Level = require("./src/levels/level.js");
// Initialise first level 1-1.js at startPosition 0
var player = new Player(keys, window);
var level = new Level(require("./src/levels/1-1.js"), keys, player);
var level = new Level(require("./src/levels/1-2.js"), keys, player);
player.pos.x = level.startPos[0].x / 1;
player.pos.y = level.startPos[0].y / 1;
player.level = level;
@ -42,6 +42,7 @@ function switchLevel(module, pos = 0) {
var items = player.items;
player = new Player(keys, window);
e = new Level(module, keys, player);
level = e;
player.pos.x = level.startPos[pos].x / 1;
player.pos.y = level.startPos[pos].y / 1;
player.items = items;
@ -64,9 +65,9 @@ game.run(() => {
// Switch to another level
if (level.switch) {
console.log("Switching level!", level);
switchLevel(require(level.switch.module), level.switch.pos);
delete level.switch;
console.log(player);
level.switch = undefined;
}
// Refocus camera to player when player is moved by a portal
@ -74,6 +75,8 @@ game.run(() => {
camera.setSubject(player);
player.refocus = false;
}
});