Added level switching

This commit is contained in:
Arne van Iterson 2020-04-08 10:14:24 +02:00
parent 7832563728
commit 5a7573d9ae
5 changed files with 38 additions and 21 deletions

View File

@ -39,13 +39,15 @@ class Player extends TileSprite {
this.lives = 5; this.lives = 5;
this.key = false; this.key = false;
this.repellant = true; this.repellant = false;
this.stamina = { this.stamina = {
current: 5, current: 5,
max: 5 max: 5
}; };
this.refocus = false;
this.hitBox = { this.hitBox = {
x: 4, x: 4,
y: 0, y: 0,

View File

@ -20,7 +20,8 @@ const keys = new KeyControls();
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-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; player.level = level;
// Lightsource makes the games extremely laggy for some reason, ill have to check the performance // 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(player);
//camera.add(lightsource); //camera.add(lightsource);
// function switchLevel(camera, module) { function switchLevel(module) {
// camera.map(function(e) { camera.map(function(e) {
// camera.remove(e); camera.remove(e);
// if (e instanceof Level) { if (e instanceof Level) {
// e = new Level(module, keys, player); player = new Player(keys, window);
// player.pos = level.startPos; e = new Level(module, keys, player);
// player.level = level; player.pos.x = level.startPos.x / 1;
// camera.add(e); player.pos.y = level.startPos.y / 1;
// camera.add(player); player.level = e;
// }
// }); camera.add(e);
// } camera.add(player);
camera.setSubject(player);
}
});
}
game.run(() => { game.run(() => {
if (mouseAim.isDown) { if (mouseAim.isDown) {
console.log("cliccccccccccc"); 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;
} }
}); });

View File

@ -30,7 +30,7 @@ let level = {
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }}, { type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * 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: "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}
] ]
}; };

View File

@ -30,7 +30,7 @@ let level = {
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }}, { type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * 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: "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}
] ]
}; };

View File

@ -32,13 +32,13 @@ class Level extends TileMap {
let e = level.entities[index]; let e = level.entities[index];
switch (e.type) { switch (e.type) {
case "Mage": 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; break;
case "Chest": 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; break;
case "Portal": 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; break;
} }
this.children.push(e.entity); this.children.push(e.entity);