feat(#8): improve debug

This commit is contained in:
Juan Sebastián Montoya 2024-09-14 18:38:50 -05:00
parent 4e2905cf96
commit 731a32303a
8 changed files with 84 additions and 88 deletions

View file

@ -1,12 +1,10 @@
import { TILE_SIZE } from "../constants.js";
import { GameObject } from "./game-object.js";
import { MapManagement } from "./map-management.js";
export class Camera extends GameObject {
constructor({ mapManagement, x = 0, y = 0, width = 160, height = 120 }) {
constructor({ gameObjects = [], x = 0, y = 0, width = 160, height = 120 }) {
super({ x, y });
this.mapManagement = mapManagement;
this.gameObjects = [mapManagement];
this.gameObjects = gameObjects;
this.x = x;
this.y = y;
this.width = width;
@ -48,19 +46,14 @@ export class Camera extends GameObject {
}
moveCamera(dx, dy, delta) {
const { levelConfig } = this.mapManagement.selected;
const layer = levelConfig.layers[0];
const { height, width } = layer;
const floorX = dx > 0 ? Math.floor : Math.ceil;
const floorY = dy > 0 ? Math.floor : Math.ceil;
const [item] = this.gameObjects;
const { height, width } = item.selected ?? item;
this.x = Math.min(
Math.max(this.x + floorX(dx * (delta * 100)), 0),
Math.max(this.x + dx * Math.floor(delta * 100), 0),
width * TILE_SIZE - this.width
);
this.y = Math.min(
Math.max(this.y + floorY(dy * (delta * 100)), 0),
Math.max(this.y + dy * Math.floor(delta * 100), 0),
height * TILE_SIZE - this.height
);
}