Added keys, repellant and started level switching
This commit is contained in:
parent
67ffda0154
commit
353d548771
6
package-lock.json
generated
6
package-lock.json
generated
@ -151,9 +151,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"asdf-games": {
|
"asdf-games": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.12",
|
||||||
"resolved": "https://registry.npmjs.org/asdf-games/-/asdf-games-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/asdf-games/-/asdf-games-1.0.12.tgz",
|
||||||
"integrity": "sha512-PXk+PKlm932HHMEsiaKsWwiC/+ZnbBSISqy80Pin8p8TM51P4Sec6iBjyIJ38SbCiDOqZqCc/fGDf0dSQoBHVg=="
|
"integrity": "sha512-XaramOeOnLK4eH3HRRR6joCQClvuZZ/ANBEjKzMpMHsZ/+O/G3arMI2h6KQ86yrWrT0TZGTc89vrfmBhQmqNrQ=="
|
||||||
},
|
},
|
||||||
"astral-regex": {
|
"astral-regex": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"author": "McArn",
|
"author": "McArn",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asdf-games": "^1.0.11"
|
"asdf-games": "^1.0.12"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^8.0.2",
|
"electron": "^8.0.2",
|
||||||
|
@ -60,8 +60,14 @@ 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);
|
||||||
|
|
||||||
this.pos.x += r.x;
|
if (this.player.repellant) {
|
||||||
this.pos.y += r.y;
|
this.pos.x -= r.x;
|
||||||
|
this.pos.y -= r.y;
|
||||||
|
} else {
|
||||||
|
this.pos.x += r.x;
|
||||||
|
this.pos.y += r.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Math.abs(r.x) > Math.abs(r.y)) {
|
if (Math.abs(r.x) > Math.abs(r.y)) {
|
||||||
// Animation x axis
|
// Animation x axis
|
||||||
|
@ -37,6 +37,10 @@ class Player extends TileSprite {
|
|||||||
this.anims.play("walk_s");
|
this.anims.play("walk_s");
|
||||||
|
|
||||||
this.lives = 5;
|
this.lives = 5;
|
||||||
|
|
||||||
|
this.key = false;
|
||||||
|
this.repellant = true;
|
||||||
|
|
||||||
this.stamina = {
|
this.stamina = {
|
||||||
current: 5,
|
current: 5,
|
||||||
max: 5
|
max: 5
|
||||||
|
@ -5,13 +5,16 @@ const { Texture, TileSprite, entity } = asdf;
|
|||||||
var texture = new Texture("./res/tilemap.png");
|
var texture = new Texture("./res/tilemap.png");
|
||||||
|
|
||||||
class Portal extends TileSprite {
|
class Portal extends TileSprite {
|
||||||
constructor(pos, player, type, action) {
|
constructor(pos, player, keys, type, action, key) {
|
||||||
super(texture, 32, 32);
|
super(texture, 32, 32);
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.scale = { x: 1, y: 1 };
|
this.scale = { x: 1, y: 1 };
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
|
|
||||||
|
this.keys = keys;
|
||||||
|
this.key = key;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "Door":
|
case "Door":
|
||||||
this.frame = { x: 1, y: 7 };
|
this.frame = { x: 1, y: 7 };
|
||||||
@ -45,8 +48,16 @@ class Portal extends TileSprite {
|
|||||||
|
|
||||||
update(dt) {
|
update(dt) {
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
if (entity.hit(this, this.player)) {
|
if (entity.hit(this, this.player) && this.keys.action) {
|
||||||
this.action();
|
if (this.key) {
|
||||||
|
if (this.player.key) {
|
||||||
|
this.action();
|
||||||
|
} else {
|
||||||
|
console.log("keyn't");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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, Lighting } = asdf;
|
const { Game, KeyControls, MouseControls, Camera, Lightsource } = asdf;
|
||||||
|
|
||||||
const window = { w: 640, h: 320 };
|
const window = { w: 640, h: 320 };
|
||||||
|
|
||||||
@ -17,33 +17,39 @@ 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 lightsources = [
|
|
||||||
// { x: 100, y: 50 },
|
|
||||||
// { x: 100, y: 300 },
|
|
||||||
// { x: 300, y: 50 },
|
|
||||||
// { x: 300, y: 300 },
|
|
||||||
// { x: 100, y: 500 },
|
|
||||||
// { x: 500, y: 100 }
|
|
||||||
// ];
|
|
||||||
// var lighting = new Lighting(level.x, level.y, level.w, level.h, lightsources);
|
|
||||||
|
|
||||||
|
|
||||||
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 = level.startPos;
|
||||||
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(lighting);
|
//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);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
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"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
37
src/levels/1-1 copy.js
Normal file
37
src/levels/1-1 copy.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
const tileSize = 32;
|
||||||
|
|
||||||
|
let level = {
|
||||||
|
tiles: [
|
||||||
|
1, 2, 2, 2, 2, 6, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 6,
|
||||||
|
4, 21, 22, 23, 21, 7, 0, 4, 22, 23, 21, 22, 23, 21, 22, 23, 21, 22, 23, 21, 22, 23, 21, 22, 23, 21, 22, 23, 21, 7,
|
||||||
|
4, 17, 17, 17, 17, 7, 0, 4, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 17, 7, 0, 4, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 17, 8, 2, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 22, 22, 22, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
4, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7,
|
||||||
|
14, 15, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 9
|
||||||
|
],
|
||||||
|
size: {
|
||||||
|
w: 960,
|
||||||
|
h: 480
|
||||||
|
},
|
||||||
|
startPos: {
|
||||||
|
x: 48,
|
||||||
|
y: 64
|
||||||
|
},
|
||||||
|
entities: [
|
||||||
|
{ 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}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = level;
|
@ -29,8 +29,8 @@ let level = {
|
|||||||
entities: [
|
entities: [
|
||||||
{ 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.pos = {x:512,y:256}; } },
|
{ 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}; }}
|
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; }, key: true}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@ const Portal = require("../entities/portal.js");
|
|||||||
|
|
||||||
class Level extends TileMap {
|
class Level extends TileMap {
|
||||||
constructor (level, keys, player) {
|
constructor (level, keys, player) {
|
||||||
console.log(level);
|
|
||||||
|
|
||||||
// Convert id array to tile array
|
// Convert id array to tile array
|
||||||
var levelTiles = level.tiles.map(function(e) {
|
var levelTiles = level.tiles.map(function(e) {
|
||||||
return { x: (tiles[e].x / tileSize), y: (tiles[e].y / tileSize), walkable: tiles[e].walkable };
|
return { x: (tiles[e].x / tileSize), y: (tiles[e].y / tileSize), walkable: tiles[e].walkable };
|
||||||
@ -40,7 +38,7 @@ class Level extends TileMap {
|
|||||||
e.entity = new Chest(e.pos, this.player, this.keys, () => { return e.action(this.player); });
|
e.entity = new Chest(e.pos, this.player, this.keys, () => { return e.action(this.player); });
|
||||||
break;
|
break;
|
||||||
case "Portal":
|
case "Portal":
|
||||||
e.entity = new Portal(e.pos, this.player, e.texture, () => { return e.action(this.player); });
|
e.entity = new Portal(e.pos, this.player, this.keys, e.texture, () => { return e.action(this.player); }, e.key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.children.push(e.entity);
|
this.children.push(e.entity);
|
||||||
|
Loading…
Reference in New Issue
Block a user