123 lines
3.2 KiB
JavaScript
123 lines
3.2 KiB
JavaScript
class OverworldMap {
|
|
constructor(config) {
|
|
this.gameObjects = config.gameObjects;
|
|
this.walls = config.walls || {};
|
|
|
|
this.lowerImage = new Image();
|
|
this.lowerImage.src = config.lowerSrc;
|
|
|
|
this.upperImage = new Image();
|
|
this.upperImage.src = config.upperSrc;
|
|
}
|
|
|
|
drawLowerImage(ctx, cameraPerson) {
|
|
ctx.drawImage(this.lowerImage, utils.withGrid(10.5) - cameraPerson.x, utils.withGrid(6) - cameraPerson.y);
|
|
}
|
|
|
|
drawUpperImage(ctx, cameraPerson) {
|
|
ctx.drawImage(this.upperImage, utils.withGrid(10.5) - cameraPerson.x, utils.withGrid(6) - cameraPerson.y);
|
|
}
|
|
|
|
isSpaceTaken(currentX, currentY, direction) {
|
|
const {x, y} = utils.nextPosition(currentX, currentY, direction);
|
|
return this.walls[`${x},${y}`] || false;
|
|
}
|
|
|
|
mountObjects() {
|
|
Object.values(this.gameObjects).forEach(o => {
|
|
// todoL determine if this object should actually mount
|
|
|
|
o.mount(this);
|
|
})
|
|
}
|
|
|
|
addWall(x, y) {
|
|
this.walls[`${x},${y}`] = true;
|
|
}
|
|
|
|
removeWall(x, y) {
|
|
delete this.walls[`${x},${y}`];
|
|
}
|
|
|
|
moveWall(wasX, wasY, direction) {
|
|
this.removeWall(wasX, wasY);
|
|
const {x, y} = utils.nextPosition(wasX, wasY, direction);
|
|
this.addWall(x, y);
|
|
}
|
|
}
|
|
|
|
window.OverworldMaps = {
|
|
DemoRoom: {
|
|
lowerSrc: "/images/maps/map-room-entrance.png",
|
|
upperSrc: "",
|
|
gameObjects: {
|
|
hero: new Person({
|
|
isPlayerControlled: true,
|
|
x: utils.withGrid(8),
|
|
y: utils.withGrid(2),
|
|
}),
|
|
// npc1: new Person({
|
|
// x: utils.withGrid(6),
|
|
// y: utils.withGrid(7),
|
|
// })
|
|
},
|
|
walls: {
|
|
// "16,16": true
|
|
[utils.asGridCoord(5,2)] : true,
|
|
[utils.asGridCoord(5,3)] : true,
|
|
[utils.asGridCoord(5,4)] : true,
|
|
[utils.asGridCoord(4,4)] : true,
|
|
[utils.asGridCoord(3,4)] : true,
|
|
[utils.asGridCoord(2,4)] : true,
|
|
[utils.asGridCoord(1,5)] : true,
|
|
[utils.asGridCoord(0,6)] : true,
|
|
[utils.asGridCoord(1,7)] : true,
|
|
[utils.asGridCoord(2,8)] : true,
|
|
[utils.asGridCoord(3,8)] : true,
|
|
[utils.asGridCoord(4,8)] : true,
|
|
[utils.asGridCoord(5,8)] : true,
|
|
[utils.asGridCoord(5,9)] : true,
|
|
[utils.asGridCoord(5,10)] : true,
|
|
[utils.asGridCoord(4,11)] : true,
|
|
[utils.asGridCoord(5,12)] : true,
|
|
[utils.asGridCoord(6,12)] : true,
|
|
[utils.asGridCoord(7,12)] : true,
|
|
[utils.asGridCoord(7,13)] : true,
|
|
[utils.asGridCoord(8,14)] : true,
|
|
[utils.asGridCoord(9,13)] : true,
|
|
[utils.asGridCoord(9,12)] : true,
|
|
[utils.asGridCoord(10,12)] : true,
|
|
[utils.asGridCoord(11,12)] : true,
|
|
[utils.asGridCoord(12,11)] : true,
|
|
[utils.asGridCoord(11,10)] : true,
|
|
[utils.asGridCoord(11,9)] : true,
|
|
[utils.asGridCoord(11,8)] : true,
|
|
[utils.asGridCoord(11,7)] : true,
|
|
[utils.asGridCoord(11,6)] : true,
|
|
[utils.asGridCoord(12,5)] : true,
|
|
[utils.asGridCoord(11,4)] : true,
|
|
[utils.asGridCoord(11,3)] : true,
|
|
[utils.asGridCoord(11,2)] : true,
|
|
[utils.asGridCoord(10,1)] : true,
|
|
[utils.asGridCoord(9,1)] : true,
|
|
[utils.asGridCoord(8,1)] : true,
|
|
[utils.asGridCoord(7,1)] : true,
|
|
[utils.asGridCoord(6,1)] : true,
|
|
}
|
|
},
|
|
Kitchen: {
|
|
lowerSrc: "/images/maps/room-builder.png",
|
|
upperSrc: "/images/maps/room-builder.png",
|
|
gameObjects: {
|
|
hero: new GameObject({
|
|
x: 2,
|
|
y: 3,
|
|
}),
|
|
npc1: new GameObject({
|
|
x: 3,
|
|
y: 6,
|
|
src: "/images/characters/people/hero-run.png"
|
|
})
|
|
}
|
|
}
|
|
} |