Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Check(Point cord, bool diagonals = false)
- {
- int edgestate = 0;
- if (cord.x > 0 && grid[cord.x - 1, cord.y] == Tile.Empty)
- {
- edgestate++;
- }
- if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y] == Tile.Empty)
- {
- edgestate += 2;
- }
- if (cord.y > 0 && grid[cord.x, cord.y - 1] == Tile.Empty)
- {
- edgestate += 4;
- }
- if (cord.y < gridheight - 1 && grid[cord.x, cord.y + 1] == Tile.Empty)
- {
- edgestate += 8;
- }
- if (!diagonals)
- {
- if (edgestate == 1)
- {
- if (cord.x < gridlength - 1)
- {
- if (cord.y > 0 && grid[cord.x + 1, cord.y - 1] == Tile.Empty)
- {
- return false;
- }
- if (cord.y < gridheight - 1 && grid[cord.x + 1, cord.y + 1] == Tile.Empty)
- {
- return false;
- }
- }
- return true;
- }
- else if (edgestate == 2)
- {
- if (cord.x > 0)
- {
- if (cord.y > 0 && grid[cord.x - 1, cord.y - 1] == Tile.Empty)
- {
- return false;
- }
- if (cord.y < gridheight - 1 && grid[cord.x - 1, cord.y + 1] == Tile.Empty)
- {
- return false;
- }
- }
- return true;
- }
- else if (edgestate == 4)
- {
- if (cord.y < gridheight - 1)
- {
- if (cord.x > 0 && grid[cord.x - 1, cord.y + 1] == Tile.Empty)
- {
- return false;
- }
- if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y + 1] == Tile.Empty)
- {
- return false;
- }
- }
- return true;
- }
- else if (edgestate == 8)
- {
- if (cord.y > 0)
- {
- if (cord.x > 0 && grid[cord.x - 1, cord.y - 1] == Tile.Empty)
- {
- return false;
- }
- if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y - 1] == Tile.Empty)
- {
- return false;
- }
- }
- return true;
- }
- return false;
- }
- else
- {
- if (edgestate == 1 || edgestate == 2 || edgestate == 4 || edgestate == 8)
- {
- return true;
- }
- return false;
- }
- }
- // This function creates a space on the grid and updates the frontier
- void Carve(Point point)
- {
- extra = new List<Point>();
- grid [point.x, point.y] = Tile.Empty;
- if (point.y > 0 && grid[point.x, point.y - 1] == Tile.Unknown)
- {
- grid[point.x, point.y - 1] = Tile.Processing;
- extra.Add(new Point(point.x, point.y - 1));
- }
- if (point.y < gridlength - 1 && grid[point.x, point.y + 1] == Tile.Unknown)
- {
- grid[point.x, point.y + 1] = Tile.Processing;
- extra.Add(new Point(point.x, point.y + 1));
- }
- if (point.x > 0 && grid[point.x - 1, point.y] == Tile.Unknown)
- {
- grid[point.x - 1, point.y] = Tile.Processing;
- extra.Add(new Point(point.x - 1, point.y));
- }
- if (point.x < gridheight - 1 && grid[point.x + 1, point.y] == Tile.Unknown)
- {
- grid[point.x + 1, point.y] = Tile.Processing;
- extra.Add(new Point(point.x + 1, point.y));
- }
- RandomizeList(extra);
- frontier.AddRange(extra);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement