feat(#10): allow multiple layers

This commit is contained in:
Juan Sebastián Montoya 2024-09-14 23:19:41 -05:00
parent 1cac9b90bc
commit e2c439d1f3
4 changed files with 112 additions and 101 deletions

View file

@ -3,10 +3,18 @@ import { createCanvas } from "../utils.js";
import { GameObject } from "./game-object.js";
export class Map extends GameObject {
constructor({ name, imageId, elementId, selected = false, debug = false }) {
constructor({
name,
imageId,
elementId,
layer = 0,
selected = false,
debug = false,
}) {
super({ debug });
this.name = name;
this.imageId = imageId;
this.layer = layer;
this.image = document.getElementById(imageId);
this.imageWidth = this.image.width;
this.imageHeight = this.image.height;
@ -16,9 +24,11 @@ export class Map extends GameObject {
}
async load() {
const levelConfig = await fetch("/resources/" + this.name + ".json");
this.levelConfig = await levelConfig.json();
const layer = this.levelConfig.layers[0];
const response = await fetch(`/resources/${this.name}.json`, {
cache: "force-cache",
});
this.levelConfig = await response.json();
const layer = this.levelConfig.layers[this.layer];
const { data, height, width } = layer;
this.width = width;
this.height = height;