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": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/asdf-games/-/asdf-games-1.0.11.tgz",
|
||||
"integrity": "sha512-PXk+PKlm932HHMEsiaKsWwiC/+ZnbBSISqy80Pin8p8TM51P4Sec6iBjyIJ38SbCiDOqZqCc/fGDf0dSQoBHVg=="
|
||||
"version": "1.0.12",
|
||||
"resolved": "https://registry.npmjs.org/asdf-games/-/asdf-games-1.0.12.tgz",
|
||||
"integrity": "sha512-XaramOeOnLK4eH3HRRR6joCQClvuZZ/ANBEjKzMpMHsZ/+O/G3arMI2h6KQ86yrWrT0TZGTc89vrfmBhQmqNrQ=="
|
||||
},
|
||||
"astral-regex": {
|
||||
"version": "1.0.0",
|
||||
|
@ -10,7 +10,7 @@
|
||||
"author": "McArn",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"asdf-games": "^1.0.11"
|
||||
"asdf-games": "^1.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^8.0.2",
|
||||
|
@ -60,8 +60,14 @@ class Mage extends TileSprite {
|
||||
const yo = Math.sin(angle) * 100 * dt;
|
||||
const r = wallslide.wallslide(this, this.level, xo, yo);
|
||||
|
||||
if (this.player.repellant) {
|
||||
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)) {
|
||||
// Animation x axis
|
||||
|
@ -37,6 +37,10 @@ class Player extends TileSprite {
|
||||
this.anims.play("walk_s");
|
||||
|
||||
this.lives = 5;
|
||||
|
||||
this.key = false;
|
||||
this.repellant = true;
|
||||
|
||||
this.stamina = {
|
||||
current: 5,
|
||||
max: 5
|
||||
|
@ -5,13 +5,16 @@ const { Texture, TileSprite, entity } = asdf;
|
||||
var texture = new Texture("./res/tilemap.png");
|
||||
|
||||
class Portal extends TileSprite {
|
||||
constructor(pos, player, type, action) {
|
||||
constructor(pos, player, keys, type, action, key) {
|
||||
super(texture, 32, 32);
|
||||
this.pos = pos;
|
||||
this.scale = { x: 1, y: 1 };
|
||||
this.player = player;
|
||||
this.action = action;
|
||||
|
||||
this.keys = keys;
|
||||
this.key = key;
|
||||
|
||||
switch (type) {
|
||||
case "Door":
|
||||
this.frame = { x: 1, y: 7 };
|
||||
@ -45,8 +48,16 @@ class Portal extends TileSprite {
|
||||
|
||||
update(dt) {
|
||||
super.update(dt);
|
||||
if (entity.hit(this, this.player)) {
|
||||
if (entity.hit(this, this.player) && this.keys.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");
|
||||
// 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 };
|
||||
|
||||
@ -17,33 +17,39 @@ var Level = require("./src/levels/level.js");
|
||||
const mouseAim = new MouseControls(document.getElementById("board"));
|
||||
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 level = new Level(require("./src/levels/1-1.js"), keys, player);
|
||||
player.pos = level.startPos;
|
||||
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 });
|
||||
|
||||
scene.add(camera);
|
||||
camera.add(level);
|
||||
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(() => {
|
||||
if (mouseAim.isDown) {
|
||||
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: [
|
||||
{ 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.pos = {x:512,y:256}; } },
|
||||
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", 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}; }, key: true}
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -12,8 +12,6 @@ const Portal = require("../entities/portal.js");
|
||||
|
||||
class Level extends TileMap {
|
||||
constructor (level, keys, player) {
|
||||
console.log(level);
|
||||
|
||||
// Convert id array to tile array
|
||||
var levelTiles = level.tiles.map(function(e) {
|
||||
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); });
|
||||
break;
|
||||
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;
|
||||
}
|
||||
this.children.push(e.entity);
|
||||
|
Loading…
Reference in New Issue
Block a user