Added level switching
This commit is contained in:
parent
7832563728
commit
5a7573d9ae
@ -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,
|
||||||
|
45
src/game.js
45
src/game.js
@ -20,11 +20,12 @@ 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
|
||||||
//var lightsource = new Lightsource(player.pos.x, player.pos.y, level.pos.x, level.pos.y, level.w, level.h);
|
// var lightsource = new Lightsource(player.pos.x, player.pos.y, level.pos.x, level.pos.y, level.w, level.h);
|
||||||
|
|
||||||
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 });
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user