From 5517fd0110cade235672cdb531f730337a67e648 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 3 Feb 2023 18:02:44 -0800 Subject: [PATCH] Clean up grid generation in setUp() --- assets/scripts/nethack/dungeon.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/assets/scripts/nethack/dungeon.js b/assets/scripts/nethack/dungeon.js index 6882d8b..a9b0c17 100644 --- a/assets/scripts/nethack/dungeon.js +++ b/assets/scripts/nethack/dungeon.js @@ -342,22 +342,15 @@ new p5(p => { p.pixelDensity(p.displayDensity()); p.textFont("Courier"); - grid = new Grid(Math.ceil(canvasWidth / CELL_WIDTH), Math.ceil(canvasHeight / CELL_HEIGHT)); - let bsp = new BSPNode(0, 0, grid.width, grid.height); - bsp.divideRecursively(); + const gridBounds = Rect.fromCoordinates( + 0, 0, + Math.ceil(canvasWidth / CELL_WIDTH) - 1, Math.ceil(canvasHeight / CELL_HEIGHT) - 1 + ); - for (let room of bsp.rooms) { - for (let y = room.y; y <= room.maxY; y++) { - for (let x = room.x; x <= room.maxX; x++) { - let charAtXY = room.charAt(x, y); - if (charAtXY) { - let cell = grid.cellAt(x, y); - cell.character = charAtXY; - cell.characterColor = p.color(255); - } - } - } - } + console.log(`Generating grid with size ${gridBounds.size.width} x ${gridBounds.size.height}`); + + grid = new Grid(gridBounds.size.width, gridBounds.size.height); + grid.generate(p, new NRandomRoomsGenerator(gridBounds)); } p.draw = () => {