import { COLS, ROWS, TILE_SIZE } from "../constants.js"; import { GameObject } from "./game-object.js"; export class Debug extends GameObject { constructor({ debug = false }) { super(); this.debug = debug; this.fps = 0; } toggle() { this.debug = !this.debug; } update(delta) { this.fps = Math.floor(1 / delta); } render(ctx) { if (!this.debug) { return; } for (let row = 0; row < ROWS; row++) { for (let col = 0; col < COLS; col++) { ctx.strokeRect(col * TILE_SIZE, row * TILE_SIZE, TILE_SIZE, TILE_SIZE); } } ctx.fillStyle = "Red"; ctx.font = "normal 16pt Arial"; ctx.fillText(this.fps + " fps", 10, 26); } onMouseClick(elementId) { if (elementId === "debug") { this.toggle(); } } }