Added level switching
This commit is contained in:
parent
7832563728
commit
5a7573d9ae
@ -39,13 +39,15 @@ class Player extends TileSprite {
|
||||
this.lives = 5;
|
||||
|
||||
this.key = false;
|
||||
this.repellant = true;
|
||||
this.repellant = false;
|
||||
|
||||
this.stamina = {
|
||||
current: 5,
|
||||
max: 5
|
||||
};
|
||||
|
||||
this.refocus = false;
|
||||
|
||||
this.hitBox = {
|
||||
x: 4,
|
||||
y: 0,
|
||||
|
43
src/game.js
43
src/game.js
@ -20,7 +20,8 @@ const keys = new KeyControls();
|
||||
var player = new Player(keys, window);
|
||||
|
||||
var level = new Level(require("./src/levels/1-1.js"), keys, player);
|
||||
player.pos = level.startPos;
|
||||
player.pos.x = level.startPos.x / 1;
|
||||
player.pos.y = level.startPos.y / 1;
|
||||
player.level = level;
|
||||
|
||||
// Lightsource makes the games extremely laggy for some reason, ill have to check the performance
|
||||
@ -33,23 +34,37 @@ camera.add(level);
|
||||
camera.add(player);
|
||||
//camera.add(lightsource);
|
||||
|
||||
// function switchLevel(camera, module) {
|
||||
// camera.map(function(e) {
|
||||
// camera.remove(e);
|
||||
// if (e instanceof Level) {
|
||||
// e = new Level(module, keys, player);
|
||||
// player.pos = level.startPos;
|
||||
// player.level = level;
|
||||
// camera.add(e);
|
||||
// camera.add(player);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
function switchLevel(module) {
|
||||
camera.map(function(e) {
|
||||
camera.remove(e);
|
||||
if (e instanceof Level) {
|
||||
player = new Player(keys, window);
|
||||
e = new Level(module, keys, player);
|
||||
player.pos.x = level.startPos.x / 1;
|
||||
player.pos.y = level.startPos.y / 1;
|
||||
player.level = e;
|
||||
|
||||
camera.add(e);
|
||||
camera.add(player);
|
||||
camera.setSubject(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
game.run(() => {
|
||||
if (mouseAim.isDown) {
|
||||
console.log("cliccccccccccc");
|
||||
switchLevel(camera, require("./src/levels/1-1 copy.js"));
|
||||
}
|
||||
|
||||
if (level.switch) {
|
||||
switchLevel(require(level.switch));
|
||||
delete level.switch;
|
||||
console.log(player);
|
||||
}
|
||||
|
||||
if (player.refocus) {
|
||||
camera.setSubject(player);
|
||||
player.refocus = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -30,7 +30,7 @@ let level = {
|
||||
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
|
||||
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * tileSize }},
|
||||
{ type: "Chest", pos: { x: 4 * tileSize, y: 2 * tileSize }, action: (player) => { player.key = true; } },
|
||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; }, key: true}
|
||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; player.refocus = true; }, key: true}
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ let level = {
|
||||
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
|
||||
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * tileSize }},
|
||||
{ type: "Chest", pos: { x: 4 * tileSize, y: 2 * tileSize }, action: (player) => { player.key = true; } },
|
||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; }, key: true}
|
||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player, level) => { level.switch = "./src/levels/1-1 copy.js"; }, key: true}
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -32,13 +32,13 @@ class Level extends TileMap {
|
||||
let e = level.entities[index];
|
||||
switch (e.type) {
|
||||
case "Mage":
|
||||
e.entity = new Mage(e.pos, this.player, this);
|
||||
e.entity = new Mage({ x: e.pos.x / 1, y: e.pos.y / 1 }, this.player, this);
|
||||
break;
|
||||
case "Chest":
|
||||
e.entity = new Chest(e.pos, this.player, this.keys, () => { return e.action(this.player); });
|
||||
e.entity = new Chest({ x: e.pos.x / 1, y: e.pos.y / 1 }, this.player, this.keys, () => { return e.action(this.player); });
|
||||
break;
|
||||
case "Portal":
|
||||
e.entity = new Portal(e.pos, this.player, this.keys, e.texture, () => { return e.action(this.player); }, e.key);
|
||||
e.entity = new Portal({ x: e.pos.x / 1, y: e.pos.y / 1 }, this.player, this.keys, e.texture, () => { return e.action(this.player, this); }, e.key);
|
||||
break;
|
||||
}
|
||||
this.children.push(e.entity);
|
||||
|
Loading…
Reference in New Issue
Block a user