Fixed some issues with level switching and items
This commit is contained in:
parent
5a7573d9ae
commit
4f3468ed96
@ -60,7 +60,7 @@ class Mage extends TileSprite {
|
|||||||
const yo = Math.sin(angle) * 100 * dt;
|
const yo = Math.sin(angle) * 100 * dt;
|
||||||
const r = wallslide.wallslide(this, this.level, xo, yo);
|
const r = wallslide.wallslide(this, this.level, xo, yo);
|
||||||
|
|
||||||
if (this.player.repellant) {
|
if (this.player.items.repellant) {
|
||||||
this.pos.x -= r.x;
|
this.pos.x -= r.x;
|
||||||
this.pos.y -= r.y;
|
this.pos.y -= r.y;
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,8 +38,10 @@ class Player extends TileSprite {
|
|||||||
|
|
||||||
this.lives = 5;
|
this.lives = 5;
|
||||||
|
|
||||||
this.key = false;
|
this.items = {
|
||||||
this.repellant = false;
|
key: false,
|
||||||
|
repellant: false
|
||||||
|
};
|
||||||
|
|
||||||
this.stamina = {
|
this.stamina = {
|
||||||
current: 5,
|
current: 5,
|
||||||
|
@ -22,7 +22,7 @@ class Portal extends TileSprite {
|
|||||||
x: 1,
|
x: 1,
|
||||||
y: 1,
|
y: 1,
|
||||||
w: 30,
|
w: 30,
|
||||||
h: 30
|
h: 45
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "Ladder":
|
case "Ladder":
|
||||||
@ -50,8 +50,9 @@ class Portal extends TileSprite {
|
|||||||
super.update(dt);
|
super.update(dt);
|
||||||
if (entity.hit(this, this.player) && this.keys.action) {
|
if (entity.hit(this, this.player) && this.keys.action) {
|
||||||
if (this.key) {
|
if (this.key) {
|
||||||
if (this.player.key) {
|
if (this.player.items.key) {
|
||||||
this.action();
|
this.action();
|
||||||
|
this.player.items.key = false;
|
||||||
} else {
|
} else {
|
||||||
console.log("keyn't");
|
console.log("keyn't");
|
||||||
}
|
}
|
||||||
|
32
src/game.js
32
src/game.js
@ -2,7 +2,7 @@ const { ipcRenderer, remote } = require("electron");
|
|||||||
|
|
||||||
var asdf = require("asdf-games");
|
var asdf = require("asdf-games");
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const { Game, KeyControls, MouseControls, Camera, Lightsource } = asdf;
|
const { Game, KeyControls, MouseControls, Camera } = asdf;
|
||||||
|
|
||||||
const window = { w: 640, h: 320 };
|
const window = { w: 640, h: 320 };
|
||||||
|
|
||||||
@ -11,37 +11,36 @@ ipcRenderer.send("resize", window);
|
|||||||
|
|
||||||
const { scene } = game;
|
const { scene } = game;
|
||||||
|
|
||||||
var Player = require("./src/entities/player.js");
|
|
||||||
var Level = require("./src/levels/level.js");
|
|
||||||
|
|
||||||
const mouseAim = new MouseControls(document.getElementById("board"));
|
const mouseAim = new MouseControls(document.getElementById("board"));
|
||||||
const keys = new KeyControls();
|
const keys = new KeyControls();
|
||||||
|
|
||||||
|
var Player = require("./src/entities/player.js");
|
||||||
|
var Level = require("./src/levels/level.js");
|
||||||
|
|
||||||
|
// 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-1.js"), keys, player);
|
||||||
player.pos.x = level.startPos.x / 1;
|
player.pos.x = level.startPos[0].x / 1;
|
||||||
player.pos.y = level.startPos.y / 1;
|
player.pos.y = level.startPos[0].y / 1;
|
||||||
player.level = level;
|
player.level = level;
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
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 });
|
||||||
|
|
||||||
scene.add(camera);
|
scene.add(camera);
|
||||||
camera.add(level);
|
camera.add(level);
|
||||||
camera.add(player);
|
camera.add(player);
|
||||||
//camera.add(lightsource);
|
|
||||||
|
|
||||||
function switchLevel(module) {
|
function switchLevel(module, pos = 0) {
|
||||||
camera.map(function(e) {
|
camera.map(function(e) {
|
||||||
camera.remove(e);
|
camera.remove(e);
|
||||||
if (e instanceof Level) {
|
if (e instanceof Level) {
|
||||||
|
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);
|
||||||
player.pos.x = level.startPos.x / 1;
|
player.pos.x = level.startPos[pos].x / 1;
|
||||||
player.pos.y = level.startPos.y / 1;
|
player.pos.y = level.startPos[pos].y / 1;
|
||||||
|
player.items = items;
|
||||||
player.level = e;
|
player.level = e;
|
||||||
|
|
||||||
camera.add(e);
|
camera.add(e);
|
||||||
@ -52,22 +51,27 @@ function switchLevel(module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
game.run(() => {
|
game.run(() => {
|
||||||
|
// Debugging tools
|
||||||
if (mouseAim.isDown) {
|
if (mouseAim.isDown) {
|
||||||
console.log("cliccccccccccc");
|
console.log("cliccccccccccc");
|
||||||
|
console.log(player.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Switch to another level
|
||||||
if (level.switch) {
|
if (level.switch) {
|
||||||
switchLevel(require(level.switch));
|
switchLevel(require(level.switch.module), level.switch.pos);
|
||||||
delete level.switch;
|
delete level.switch;
|
||||||
console.log(player);
|
console.log(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refocus camera to player when player is moved by a portal
|
||||||
if (player.refocus) {
|
if (player.refocus) {
|
||||||
camera.setSubject(player);
|
camera.setSubject(player);
|
||||||
player.refocus = false;
|
player.refocus = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* *********************************************************
|
/* *********************************************************
|
||||||
Settings behavior
|
Settings behavior
|
||||||
********************************************************* */
|
********************************************************* */
|
||||||
|
@ -27,10 +27,31 @@ let level = {
|
|||||||
y: 64
|
y: 64
|
||||||
},
|
},
|
||||||
entities: [
|
entities: [
|
||||||
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
|
{
|
||||||
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * tileSize }},
|
type: "Mage",
|
||||||
{ type: "Chest", pos: { x: 4 * tileSize, y: 2 * tileSize }, action: (player) => { player.key = true; } },
|
pos: { x: 9 * tileSize, y: 2 * tileSize }
|
||||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; player.refocus = true; }, key: true}
|
},
|
||||||
|
{
|
||||||
|
type: "Mage",
|
||||||
|
pos: { x: 1 * tileSize, y: 8 * tileSize }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "Chest",
|
||||||
|
pos: { x: 4 * tileSize, y: 2 * tileSize },
|
||||||
|
action: (player) => {
|
||||||
|
player.items.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
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,15 +22,35 @@ let level = {
|
|||||||
w: 960,
|
w: 960,
|
||||||
h: 480
|
h: 480
|
||||||
},
|
},
|
||||||
startPos: {
|
startPos: [
|
||||||
x: 48,
|
{ x: 48, y: 64 },
|
||||||
y: 64
|
{ x: 48, y: 128 }
|
||||||
},
|
],
|
||||||
entities: [
|
entities: [
|
||||||
{ type: "Mage", pos: { x: 9 * tileSize, y: 2 * tileSize }},
|
{
|
||||||
{ type: "Mage", pos: { x: 1 * tileSize, y: 8 * tileSize }},
|
type: "Mage",
|
||||||
{ type: "Chest", pos: { x: 4 * tileSize, y: 2 * tileSize }, action: (player) => { player.key = true; } },
|
pos: { x: 9 * tileSize, y: 2 * tileSize }
|
||||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player, level) => { level.switch = "./src/levels/1-1 copy.js"; }, key: true}
|
},
|
||||||
|
{
|
||||||
|
type: "Mage",
|
||||||
|
pos: { x: 1 * tileSize, y: 8 * tileSize }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "Chest",
|
||||||
|
pos: { x: 4 * tileSize, y: 2 * tileSize },
|
||||||
|
action: (player) => {
|
||||||
|
player.items.key = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "Portal",
|
||||||
|
pos: { x: 8 * tileSize, y: 2 * tileSize },
|
||||||
|
texture: "Ladder",
|
||||||
|
action: (player, level) => {
|
||||||
|
level.switch = { module: "./src/levels/1-1 copy.js", pos: 0 };
|
||||||
|
},
|
||||||
|
key: true
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user