Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 22x 22x 22x 18x 18x 18x 18x 18x 18x 18x 18x 3525x 3525x 1750125x 18x 36x 3500250x 1732076x 1768174x 18x | import * as ROT from "rot-js";
import { TileFactory, TileInterface } from "../index";
export class MapGenerator {
protected width: number;
protected height: number;
protected tiles: TileInterface[][];
private generator: ROT.Map;
private totalIterations = 3;
public constructor(width: number, height: number) {
this.width = width;
this.height = height;
this.tiles = [];
this.generator = new ROT.Map.Cellular(width, height);
this.generator.randomize(0.5);
}
public generate(): TileInterface[][] {
const factory = new TileFactory();
for (let x = 0; x < this.width; x++) {
this.tiles.push([]);
for (let y = 0; y < this.height; y++) {
this.tiles[x].push(factory.create("null"));
}
}
// Iteratively smoothen the map
for (let i = 0; i < this.totalIterations - 1; i++) {
this.generator.create((x: number, y: number, v: number): void => {
if (v === 1) {
this.tiles[x][y] = factory.create("floor");
} else {
this.tiles[x][y] = factory.create("wall");
}
});
}
return this.tiles;
}
}
|