Clean up grid generation in setUp()
This commit is contained in:
parent
a283cae416
commit
5517fd0110
1 changed files with 8 additions and 15 deletions
|
@ -342,22 +342,15 @@ new p5(p => {
|
||||||
p.pixelDensity(p.displayDensity());
|
p.pixelDensity(p.displayDensity());
|
||||||
p.textFont("Courier");
|
p.textFont("Courier");
|
||||||
|
|
||||||
grid = new Grid(Math.ceil(canvasWidth / CELL_WIDTH), Math.ceil(canvasHeight / CELL_HEIGHT));
|
const gridBounds = Rect.fromCoordinates(
|
||||||
let bsp = new BSPNode(0, 0, grid.width, grid.height);
|
0, 0,
|
||||||
bsp.divideRecursively();
|
Math.ceil(canvasWidth / CELL_WIDTH) - 1, Math.ceil(canvasHeight / CELL_HEIGHT) - 1
|
||||||
|
);
|
||||||
|
|
||||||
for (let room of bsp.rooms) {
|
console.log(`Generating grid with size ${gridBounds.size.width} x ${gridBounds.size.height}`);
|
||||||
for (let y = room.y; y <= room.maxY; y++) {
|
|
||||||
for (let x = room.x; x <= room.maxX; x++) {
|
grid = new Grid(gridBounds.size.width, gridBounds.size.height);
|
||||||
let charAtXY = room.charAt(x, y);
|
grid.generate(p, new NRandomRoomsGenerator(gridBounds));
|
||||||
if (charAtXY) {
|
|
||||||
let cell = grid.cellAt(x, y);
|
|
||||||
cell.character = charAtXY;
|
|
||||||
cell.characterColor = p.color(255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.draw = () => {
|
p.draw = () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue