mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Graveyard terrain and background tiles implemented
This commit is contained in:
@@ -5,9 +5,17 @@ import GraphicSet from "../../js/GraphicSet.js";
|
||||
|
||||
export default class Terrain
|
||||
{
|
||||
/**
|
||||
* @param {Tileset} tileset
|
||||
* @param {number} tilesX
|
||||
* @param {number} tilesY
|
||||
* @param {string} backgroundColor
|
||||
*/
|
||||
constructor(tileset, tilesX, tilesY, backgroundColor = 'black')
|
||||
{
|
||||
/** @type {Tileset} */
|
||||
this.tileset = tileset;
|
||||
|
||||
this.fields = [];
|
||||
this.tilesX = tilesX;
|
||||
this.tilesY = tilesY;
|
||||
@@ -19,6 +27,7 @@ export default class Terrain
|
||||
this.backgroundImage = undefined;
|
||||
this.htmlElement = document.createElement('table');
|
||||
this.brushTileIndex = 0;
|
||||
this.brushBackdroundTileIndex = 0;
|
||||
|
||||
this.init();
|
||||
}
|
||||
@@ -38,7 +47,14 @@ export default class Terrain
|
||||
(event) => {
|
||||
this.brushTileIndex = event.button.index;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
window.addEventListener(
|
||||
TilorswiftEvent.BACKGROUND_BUTTON_TILE_CLICKED,
|
||||
(event) => {
|
||||
this.brushTileIndex = event.button.index;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getElement()
|
||||
@@ -106,8 +122,6 @@ export default class Terrain
|
||||
|
||||
addColumns(index, quantity = 1)
|
||||
{
|
||||
console.log(this.fields);
|
||||
|
||||
for (let c = 0; c < quantity; c++) {
|
||||
this._insertColumn(index);
|
||||
this.tilesX++;
|
||||
@@ -122,8 +136,6 @@ export default class Terrain
|
||||
}
|
||||
|
||||
this.htmlElement.style.width = this.tileset.getTileWidth() * this.tilesX + 'px';
|
||||
|
||||
console.log(this.fields);
|
||||
}
|
||||
|
||||
_insertColumn(index = undefined)
|
||||
@@ -149,7 +161,7 @@ export default class Terrain
|
||||
|
||||
setEntrancePoint(tileX, tileY)
|
||||
{
|
||||
if (this.fields[tileY][tileX].index === -1) {
|
||||
if (this.fields[tileY][tileX].index < 0) {
|
||||
if (this.entranceTileX !== undefined && this.entranceTileY !== undefined) {
|
||||
this.fields[this.entranceTileY][this.entranceTileX].setEntrancePoint(false);
|
||||
}
|
||||
@@ -163,7 +175,7 @@ export default class Terrain
|
||||
|
||||
setTargetPoint(tileX, tileY)
|
||||
{
|
||||
if (this.fields[tileY][tileX].index === -1) {
|
||||
if (this.fields[tileY][tileX].index < 0) {
|
||||
if (this.targetTileX !== undefined && this.targetTileY !== undefined) {
|
||||
this.fields[this.targetTileY][this.targetTileX].setTargetPoint(false);
|
||||
}
|
||||
@@ -203,6 +215,7 @@ export default class Terrain
|
||||
const graphicSet = GraphicSet[levelData.tileset];
|
||||
|
||||
const tileset = new Tileset(levelData.tileset);
|
||||
|
||||
const terrain = new Terrain(tileset, levelData.columns, levelData.rows, graphicSet.backgroundColor);
|
||||
terrain.backgroundImage = graphicSet.backgroundImage ?? undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user