xxxxxxxxxx
let black;
let white;
let width = 10;
let height = 10;
let cellSize = 25;
let tiles = [];
let grid;
function setup() {
black = color(100, 100, 100);
white = color(255, 255, 255);
createCanvas(width * cellSize, height * cellSize);
background(200);
// Initialize Tiles
InitTiles();
// Initialize Grid
grid = new Grid(width, height, cellSize, tiles);
grid.Init();
// Draw Map
DrawMap();
}
function mouseClicked() {
DrawMap();
}
function DrawMap() {
//let count = 0;
//while(!grid.isCollapsed && count < width * height) {
// grid.Collapse();
// count++;
//}
grid.Collapse();
grid.Draw();
}
function InitTiles() {
let tileMasks = [
// Top // Left // Right // Bottom
[[0, 2], [0, 1], [0, 1], [0, 2]], // Empty (Walkable)
[[0], [0], [3], [4]], // TopLeft Corner
[[0], [3], [0], [4]], // TopRight Corner
[[4], [0], [3], [0]], // BottomLeft Corner
[[4], [3], [0], [0]], // BottomRight Corner
[[0], [0, 1, 3], [0, 1, 3], [0]], // Horizontal
[[0, 2, 4], [0], [0], [0, 2, 4]] // Vertical
];
for (let index = 0; index < tileMasks.length; ++index) {
tiles.push(new Tile(index, tileMasks[index], tileMasks));
}
}