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:
@@ -3,41 +3,74 @@ import Setting from "../../js/Setting.js";
|
||||
|
||||
export default class Tileset
|
||||
{
|
||||
/**
|
||||
* @param {number} setId
|
||||
*/
|
||||
constructor(setId)
|
||||
{
|
||||
/** @type {number} */
|
||||
this.setId = setId;
|
||||
|
||||
/** @type {Image} */
|
||||
this.image = new Image();
|
||||
this.image.src = '../' + Setting.TILESET_LOCATION + GraphicSet[this.setId].tileset;
|
||||
|
||||
/** @type {number} */
|
||||
this.tiles = GraphicSet[this.setId].tiles;
|
||||
|
||||
/** @type {number} */
|
||||
this.scale = GraphicSet[this.setId].scale;
|
||||
|
||||
/** @type {number} */
|
||||
this.primaryTiles = GraphicSet[this.setId].primaryTiles;
|
||||
|
||||
/** @type {{image: Image, tiles: number, scale: number}|null} */
|
||||
this.background = null;
|
||||
|
||||
if (GraphicSet[this.setId].tilesetBackground !== null) {
|
||||
const backgroundImage = new Image();
|
||||
backgroundImage.src = '../' + Setting.TILESET_LOCATION +
|
||||
GraphicSet[this.setId].tilesetBackground.path;
|
||||
|
||||
this.background = {
|
||||
image: backgroundImage,
|
||||
tiles: GraphicSet[this.setId].tilesetBackground.tiles,
|
||||
scale: GraphicSet[this.setId].tilesetBackground.scale,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** @returns {number} */
|
||||
getWidth()
|
||||
{
|
||||
return this.image.width * this.scale;
|
||||
}
|
||||
|
||||
/** @returns {number} */
|
||||
getHeight()
|
||||
{
|
||||
return this.image.height * this.scale;
|
||||
}
|
||||
|
||||
/** @returns {number} */
|
||||
getTileWidth()
|
||||
{
|
||||
return this.image.width / this.tiles * this.scale;
|
||||
}
|
||||
|
||||
/** @returns {number} */
|
||||
getTileHeight()
|
||||
{
|
||||
return this.image.height * this.scale;
|
||||
}
|
||||
|
||||
/** @returns {boolean} */
|
||||
hasExtendedTiles()
|
||||
{
|
||||
return GraphicSet[this.setId].tiles > GraphicSet[this.setId].primaryTiles ;
|
||||
}
|
||||
|
||||
/** @returns {number} */
|
||||
getTileIndexFactor(code)
|
||||
{
|
||||
const CODES = ['ltr', 't', 'r', 'b', 'l', 'lt', 'tr', 'ltb', 'tb', 'trb', 'lb', 'rb', 'ltrb', 'lr', 'lrb'];
|
||||
|
||||
Reference in New Issue
Block a user