TileNeighbors GetSurroundingTiles(Coordinates c, bool[,] boolMap) { // Remember it's bottom left origin! TileNeighbors n = new TileNeighbors(); n.C = TileExists(c, boolMap); n.N = TileExists(new Coordinates(c.x, c.y + 1), boolMap); n.NE = TileExists(new Coordinates(c.x + 1, c.y + 1), boolMap); n.E = TileExists(new Coordinates(c.x + 1, c.y), boolMap); n.SE = TileExists(new Coordinates(c.x + 1, c.y - 1), boolMap); n.S = TileExists(new Coordinates(c.x, c.y - 1), boolMap); n.SW = TileExists(new Coordinates(c.x - 1, c.y - 1), boolMap); n.W = TileExists(new Coordinates(c.x - 1, c.y), boolMap); n.NW = TileExists(new Coordinates(c.x - 1, c.y + 1), boolMap); return(n); }
public void MarchSquares() { // Build our bool map first bool[,] walls = new bool[map.width, map.height]; for (int x = 0; x < map.width; x++) { for (int y = 0; y < map.height; y++) { if (BaseWallExists(new Coordinates(x, y))) { walls [x, y] = true; } else { walls [x, y] = false; } } } for (int x = 0; x < map.width; x++) { for (int y = 0; y < map.height; y++) { // Get the tile neighbors and assign a tile based on that. Levels grow outwards from wall tiles already placed TileNeighbors ns = GetSurroundingTiles(new Coordinates(x, y), walls); if (!ns.C) { // Empty tile if (ns.S) { if (ns.E) { SetTileIfNotSet(x, y, wallLayer, 3); } else if (ns.W) { SetTileIfNotSet(x, y, wallLayer, 4); } else { SetTileIfNotSet(x, y, wallLayer, 1); } } else if (ns.E) { if (ns.N) { SetTileIfNotSet(x, y, wallLayer, 35); } else { SetTileIfNotSet(x, y, wallLayer, 32); } } else if (ns.W) { if (ns.N) { SetTileIfNotSet(x, y, wallLayer, 36); } else { SetTileIfNotSet(x, y, wallLayer, 34); } } else if (ns.N) { SetTileIfNotSet(x, y, wallLayer, 65); } else if (ns.NE) { SetTileIfNotSet(x, y, wallLayer, 64); } else if (ns.SE) { SetTileIfNotSet(x, y, wallLayer, 0); } else if (ns.NW) { SetTileIfNotSet(x, y, wallLayer, 66); } else if (ns.SW) { SetTileIfNotSet(x, y, wallLayer, 2); } } } } }