[fix]: Fixed level switching bug.
This commit is contained in:
parent
0b07ff3f2a
commit
68d2f862d5
@ -64,8 +64,7 @@ class Portal extends TileSprite {
|
|||||||
const element = this.player.items.keys[index];
|
const element = this.player.items.keys[index];
|
||||||
if (element == this.key) {
|
if (element == this.key) {
|
||||||
this.action();
|
this.action();
|
||||||
this.player.items.key = false;
|
break;
|
||||||
delete this.player.items.keys[index];
|
|
||||||
} else {
|
} else {
|
||||||
// Not the correct key
|
// Not the correct key
|
||||||
console.log("correct keyn't");
|
console.log("correct keyn't");
|
||||||
|
@ -20,7 +20,7 @@ var Level = require("./src/levels/level.js");
|
|||||||
// Initialise first level 1-1.js at startPosition 0
|
// Initialise first level 1-1.js at startPosition 0
|
||||||
var player = new Player(keys, window);
|
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.x = level.startPos[0].x / 1;
|
||||||
player.pos.y = level.startPos[0].y / 1;
|
player.pos.y = level.startPos[0].y / 1;
|
||||||
player.level = level;
|
player.level = level;
|
||||||
@ -42,6 +42,7 @@ function switchLevel(module, pos = 0) {
|
|||||||
var items = player.items;
|
var items = player.items;
|
||||||
player = new Player(keys, window);
|
player = new Player(keys, window);
|
||||||
e = new Level(module, keys, player);
|
e = new Level(module, keys, player);
|
||||||
|
level = e;
|
||||||
player.pos.x = level.startPos[pos].x / 1;
|
player.pos.x = level.startPos[pos].x / 1;
|
||||||
player.pos.y = level.startPos[pos].y / 1;
|
player.pos.y = level.startPos[pos].y / 1;
|
||||||
player.items = items;
|
player.items = items;
|
||||||
@ -64,9 +65,9 @@ game.run(() => {
|
|||||||
|
|
||||||
// Switch to another level
|
// Switch to another level
|
||||||
if (level.switch) {
|
if (level.switch) {
|
||||||
|
console.log("Switching level!", level);
|
||||||
switchLevel(require(level.switch.module), level.switch.pos);
|
switchLevel(require(level.switch.module), level.switch.pos);
|
||||||
delete level.switch;
|
level.switch = undefined;
|
||||||
console.log(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refocus camera to player when player is moved by a portal
|
// Refocus camera to player when player is moved by a portal
|
||||||
@ -74,6 +75,8 @@ game.run(() => {
|
|||||||
camera.setSubject(player);
|
camera.setSubject(player);
|
||||||
player.refocus = false;
|
player.refocus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user