Added portals and doors
This commit is contained in:
parent
02c8e5587c
commit
fe5e8cf993
54
src/entities/portal.js
Normal file
54
src/entities/portal.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
var asdf = require("asdf-games");
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const { Texture, TileSprite, entity } = asdf;
|
||||||
|
|
||||||
|
var texture = new Texture("./res/tilemap.png");
|
||||||
|
|
||||||
|
class Portal extends TileSprite {
|
||||||
|
constructor(pos, player, type, action) {
|
||||||
|
super(texture, 32, 32);
|
||||||
|
this.pos = pos;
|
||||||
|
this.scale = { x: 1, y: 1 };
|
||||||
|
this.player = player;
|
||||||
|
this.action = action;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "Door":
|
||||||
|
this.frame = { x: 1, y: 7 };
|
||||||
|
this.hitBox = {
|
||||||
|
x: 1,
|
||||||
|
y: 1,
|
||||||
|
w: 30,
|
||||||
|
h: 30
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "Ladder":
|
||||||
|
this.frame = { x: 2, y: 7 };
|
||||||
|
this.hitBox = {
|
||||||
|
x: 4,
|
||||||
|
y: 0,
|
||||||
|
w: 24,
|
||||||
|
h: 32
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "Stairs":
|
||||||
|
this.frame = { x: 4, y: 7 };
|
||||||
|
this.hitBox = {
|
||||||
|
x: 1,
|
||||||
|
y: 1,
|
||||||
|
w: 30,
|
||||||
|
h: 30
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update(dt) {
|
||||||
|
super.update(dt);
|
||||||
|
if (entity.hit(this, this.player)) {
|
||||||
|
this.action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Portal;
|
@ -1,6 +1,6 @@
|
|||||||
const tileSize = 32;
|
const tileSize = 32;
|
||||||
|
|
||||||
var level = {
|
let level = {
|
||||||
tiles: [
|
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,
|
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, 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,
|
||||||
@ -27,9 +27,10 @@ var level = {
|
|||||||
y: 64
|
y: 64
|
||||||
},
|
},
|
||||||
entities: [
|
entities: [
|
||||||
{ type: "Mage", pos: { x: 8 * 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.pos = {x:512,y:256}; } },
|
||||||
|
{ type: "Portal", pos: { x: 8 * tileSize, y: 2 * tileSize }, texture: "Ladder", action: (player) => { player.pos = {x:512,y:256}; }}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,9 +8,11 @@ const tileSize = 32;
|
|||||||
|
|
||||||
const Mage = require("../entities/mage.js");
|
const Mage = require("../entities/mage.js");
|
||||||
const Chest = require("../entities/chest.js");
|
const Chest = require("../entities/chest.js");
|
||||||
|
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) {
|
||||||
@ -29,18 +31,19 @@ class Level extends TileMap {
|
|||||||
|
|
||||||
// Handle Entities
|
// Handle Entities
|
||||||
for (let index = 0; index < level.entities.length; index++) {
|
for (let index = 0; index < level.entities.length; index++) {
|
||||||
const e = level.entities[index];
|
let e = level.entities[index];
|
||||||
var entity;
|
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case "Mage":
|
case "Mage":
|
||||||
entity = new Mage(e.pos, this.player, this);
|
e.entity = new Mage(e.pos, this.player, this);
|
||||||
break;
|
break;
|
||||||
case "Chest":
|
case "Chest":
|
||||||
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;
|
||||||
|
case "Portal":
|
||||||
|
e.entity = new Portal(e.pos, this.player, e.texture, () => { return e.action(this.player); });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
console.log(e);
|
this.children.push(e.entity);
|
||||||
this.children.push(entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user