Camera implemented.

This commit is contained in:
Mal
2020-02-09 22:06:59 +01:00
parent d43cd56d65
commit f6890eec24
8 changed files with 116 additions and 23 deletions

View File

@@ -48,6 +48,16 @@ export default class Terrain
return this.tileset;
}
getWidth()
{
return this.tilesX * this.tilest.getTileWidth();
}
getHeight()
{
return this.tilesY * this.tilest.getTileHeight();
}
addRows(index, quantity = 1)
{
for (let q = 0; q < quantity; q++) {
@@ -70,6 +80,8 @@ export default class Terrain
tr.appendChild(td);
}
console.log(row.length);
if (index === undefined || index >= this.tilesY - 1) {
this.fields.push(row);
this.htmlElement.appendChild(tr);
@@ -142,18 +154,21 @@ export default class Terrain
return this.entranceTileX !== undefined && this.entranceTileY !== undefined;
}
static createFromJson(json)
static createFromJson(terrainData)
{
let terrainData = JSON.parse(json);
let imageTileset = new Image();
imageTileset.src = terrainData.tileset;
let tileset = new Tileset(imageTileset, terrainData.tiles, terrainData.scale);
let terrain = new Terrain(tileset, terrainData.columns, terrainData.rows, terrainData.backgroundColor);
for (let y = 0; y < terrainData.matrix.length; y++) {
for (let x = 0; x < terrainData.matrix[y].length; x++) {
for (let y = 0; y < terrainData.rows; y++) {
for (let x = 0; x < terrainData.columns; x++) {
terrain.setFieldIndex(x, y, terrainData.matrix[y][x]);
if (x === terrainData.startX && y === terrainData.startY) {
terrain.setEntrancePoint(x, y);
}
}
}