public void FloodFill(int startX, int startY, int endX, int endY) { ClearPath(); Floodfill ff = GameObject.Instantiate(floodfill, Vector3.zero, Quaternion.identity).GetComponent <Floodfill>(); ff.StartFlood(startX, startY, endX, endY); }
private bool FillDisconnected(Level level) { int threshold = (int)(rect.Width * rect.Height * .4f); HashSet <Cell> cavern = new HashSet <Cell>(); int attempts = 0; do { if (attempts > 50) { UnityEngine.Debug.Log("No cavern of sufficient size" + " found, regenerating..."); return(false); } cavern = Floodfill.FillRect(level, rect, level.RandomFloorInRect(rect)); attempts++; } while (cavern.Count < threshold); foreach (Cell cell in level.CellsInRect(rect)) { if (!cell.Walled && !cavern.Contains(cell)) { cell.Terrain = wall; } } return(true); }
/// <summary> /// Change visibility and reveal new cells. /// <param name="level"></param> /// </summary> /// <returns>A HashSet of all cells affected by the refresh.</returns> public static HashSet <Cell> RefreshFOV(Level level, Cell origin, bool drawChanges) { // Hide cells at the last refresh position if (prev != null && level.Distance(prev, origin) > 1) { List <Cell> cells = level.GetSquare(prev, FOVRadius); foreach (Cell c in cells) { if (c.SetVisibility(false, -1)) { level.DrawTile(c); } } } HashSet <Cell> changed = new HashSet <Cell>(); for (int octant = 0; octant < 8; octant++) { List <Cell> refreshed = ShadowOctant(level, origin.Position, octant); changed.AddMany(refreshed); } if (drawChanges) { level.Draw(changed); } prev = origin; HashSet <Cell> visibles = Floodfill.StackFillIf( level, origin, (Cell c) => c.Visible); Locator.Player.UpdateVisibles(visibles); return(changed); }
public void Update() { if (IsMousePressed(MouseButtons.Left) && !isPressedLeft) { Floodfill.Reset(this); Floodfill.FloodFill(this, CURSOR_POSITION.X / CellSize - InitX, CURSOR_POSITION.Y / CellSize - InitY); isPressedLeft = true; } if (IsMouseReleased(MouseButtons.Left)) { isPressedLeft = false; } if (IsMousePressed(MouseButtons.Right) && !isPressedRight) { isPressedRight = true; this[CURSOR_POSITION.X / CellSize - InitX, CURSOR_POSITION.Y / CellSize - InitY].Rotate(); } if (IsMouseReleased(MouseButtons.Right)) { isPressedRight = false; } }