Fixed an issue with the stats when level switching
This commit is contained in:
parent
a57dab97ce
commit
0b508af1df
16
src/game.js
16
src/game.js
@ -27,7 +27,7 @@ player.pos.y = level.startPos[0].y / 1;
|
|||||||
player.level = level;
|
player.level = level;
|
||||||
|
|
||||||
const camera = new Camera(player, window, { w: level.w * 2, h: level.h * 2 });
|
const camera = new Camera(player, window, { w: level.w * 2, h: level.h * 2 });
|
||||||
const stats = new Stats(player);
|
var stats = new Stats(player);
|
||||||
|
|
||||||
scene.add(camera);
|
scene.add(camera);
|
||||||
camera.add(level);
|
camera.add(level);
|
||||||
@ -35,21 +35,33 @@ camera.add(player);
|
|||||||
scene.add(stats);
|
scene.add(stats);
|
||||||
|
|
||||||
function switchLevel(module, pos = 0) {
|
function switchLevel(module, pos = 0) {
|
||||||
|
scene.remove(stats);
|
||||||
|
console.log(scene);
|
||||||
camera.map(function(e) {
|
camera.map(function(e) {
|
||||||
camera.remove(e);
|
camera.remove(e);
|
||||||
if (e instanceof Level) {
|
if (e instanceof Level) {
|
||||||
|
var lives = player.lives;
|
||||||
var items = player.items;
|
var items = player.items;
|
||||||
player = new Player(keys, window);
|
|
||||||
|
var p = new Player(keys, window);
|
||||||
|
player = p;
|
||||||
|
|
||||||
e = new Level(module, keys, player);
|
e = new Level(module, keys, player);
|
||||||
level = e;
|
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.lives = lives;
|
||||||
player.items = items;
|
player.items = items;
|
||||||
player.level = e;
|
player.level = e;
|
||||||
|
|
||||||
|
stats = new Stats(player);
|
||||||
|
|
||||||
camera.add(e);
|
camera.add(e);
|
||||||
camera.add(player);
|
camera.add(player);
|
||||||
camera.setSubject(player);
|
camera.setSubject(player);
|
||||||
|
scene.add(stats);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user