public override void Apply(Dungeon dungeon, DungeonFloor floor) { List <DungeonRegion> pruned = new List <DungeonRegion>(); foreach (DungeonRegion region in floor.Regions) { if (region.Size.x < minWidth || region.Size.y < minHeight) { pruned.Add(region); if (region.Neighbors.Count > 0) { DungeonRegion inheritor = region.Neighbors[Random.Range(0, region.Neighbors.Count)]; region.Neighbors.Remove(inheritor); inheritor.Neighbors.Remove(region); foreach (DungeonRegion neighbor in region.Neighbors) { neighbor.Neighbors.Remove(region); inheritor.Neighbors.Add(neighbor); neighbor.Neighbors.Add(inheritor); } } } } floor.Regions.RemoveAll(region => pruned.Contains(region)); }
private DungeonRegion[] Split(DungeonRegion region) { if (CanSplitVertically(region) && CanSplitHorizontally(region)) { return(Random.Range(0f, 1f) < .5f ? SplitVertically(region) : SplitHorizontally(region)); } return(CanSplitVertically(region) ? SplitVertically(region) : SplitHorizontally(region)); }
public void ForTilesInRegion(DungeonRegion region, TileDecoratorDelegate tileDecoratorDelegate) { for (int x = region.Position.x; x < region.Position.x + region.Size.x; x++) { for (int y = region.Position.y; y < region.Position.y + region.Size.y; y++) { Tiles[x, y] = tileDecoratorDelegate(x, y, Tiles[x, y]); } } }
public DungeonFloor(int width, int height, RLTileType defaultType) { Tags = new List <string>(); DungeonRegion mainRegion = new DungeonRegion(new Vector2Int(0, 0), new Vector2Int(width, height)); Regions = new List <DungeonRegion> { mainRegion }; Tiles = new RLBaseTile[width, height]; ForTilesInRegion(mainRegion, (x, y, tile) => new RLSimpleTile(new Vector3Int(x, y, 0), defaultType, this)); }
public override void Apply(Dungeon dungeon, DungeonFloor floor) { foreach (DungeonRegion reg in floor.Regions) { DungeonRegion region = reg; floor.ForTilesInRegion(reg, (x, y, tile) => { if (x == region.Position.x || x == region.Position.x + region.Size.x - 1 || y == region.Position.y || y == region.Position.y + region.Size.y - 1) { tile.SetTileType(wallType); } else { tile.SetTileType(floorType); } return(tile); }); } }
private DungeonRegion[] SplitVertically(DungeonRegion region) { int bottomHeight = Mathf.Max(1, region.Size.y / 2 + Random.Range(-splitVariance, splitVariance + 1)); DungeonRegion bottom = new DungeonRegion(new Vector2Int(region.Position.x, region.Position.y), new Vector2Int(region.Size.x, bottomHeight)); bottom.Tags.AddRange(region.Tags); DungeonRegion top = new DungeonRegion(new Vector2Int(region.Position.x, region.Position.y + bottomHeight), new Vector2Int(region.Size.x, region.Size.y - bottomHeight)); top.Tags.AddRange(region.Tags); bottom.Neighbors.Add(top); top.Neighbors.Add(bottom); foreach (DungeonRegion neighbor in region.Neighbors) { neighbor.Neighbors.Remove(region); DungeonRegion newNeighbor = Random.Range(0f, 1f) < .5f ? top : bottom; newNeighbor.Neighbors.Add(neighbor); neighbor.Neighbors.Add(newNeighbor); } return(new[] { bottom, top }); }
private DungeonRegion[] SplitHorizontally(DungeonRegion region) { int leftWidth = Mathf.Max(1, region.Size.x / 2 + Random.Range(-splitVariance, splitVariance + 1)); DungeonRegion left = new DungeonRegion(new Vector2Int(region.Position.x, region.Position.y), new Vector2Int(leftWidth, region.Size.y)); left.Tags.AddRange(region.Tags); DungeonRegion right = new DungeonRegion(new Vector2Int(region.Position.x + leftWidth, region.Position.y), new Vector2Int(region.Size.x - leftWidth, region.Size.y)); right.Tags.AddRange(region.Tags); left.Neighbors.Add(right); right.Neighbors.Add(left); foreach (DungeonRegion neighbor in region.Neighbors) { neighbor.Neighbors.Remove(region); DungeonRegion newNeighbor = Random.Range(0f, 1f) < .5f ? left : right; newNeighbor.Neighbors.Add(neighbor); neighbor.Neighbors.Add(newNeighbor); } return(new[] { left, right }); }
private bool CanSplitHorizontally(DungeonRegion region) { return(splitHorizontally && region.Size.x > minDimensions.x); }
private bool CanSplitVertically(DungeonRegion region) { return(splitVertically && region.Size.y > minDimensions.y); }