initial commit
This commit is contained in:
47
GameMap.js
Normal file
47
GameMap.js
Normal file
@@ -0,0 +1,47 @@
|
||||
class GameMap {
|
||||
constructor(tiles, spawn) {
|
||||
this.width = tiles.length;
|
||||
this.height = tiles[0].length;
|
||||
this.tiles = tiles;
|
||||
this.spawn = spawn;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.tiles.forEach(row => {
|
||||
row.forEach(tile => {
|
||||
if(tile.solid) {
|
||||
tile.lookAtNeighbours(this.getSurroundingTiles(tile.x, tile.y));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
draw(ctx, conf) {
|
||||
this.tiles.forEach(col => {
|
||||
col.forEach(tile => {
|
||||
tile.draw(ctx, conf);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getTile(x, y) {
|
||||
try {
|
||||
return this.tiles[x][y];
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
getSurroundingTiles(x, y) {
|
||||
const left = this.getTile(x - 1, y);
|
||||
const right = this.getTile(x + 1, y);
|
||||
const top = this.getTile(x, y - 1);
|
||||
const bottom = this.getTile(x, y + 1);
|
||||
|
||||
return {
|
||||
left, top, right, bottom
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user