Clean up grid generation in setUp()

This commit is contained in:
Eryn Wells 2023-02-03 18:02:44 -08:00
parent a283cae416
commit 5517fd0110

View file

@ -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 = () => {