private void NextStep(List <CellMaze> activeCells) { int currentIndex = activeCells.Count - 1; CellMaze currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } DirectionMaze direction = currentCell.RandomUninitializedDirection; IntVector coordinates = currentCell.coordinates + direction.ToIntVector(); if (ContainsCoordinates(coordinates)) { CellMaze neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void CreatePassage(CellMaze cell, CellMaze otherCell, DirectionMaze direction) { PassageMaze passage = Instantiate(passagePrefab) as PassageMaze; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as PassageMaze; passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private CellMaze CreateCell(IntVector coordinates) { CellMaze newCell = Instantiate(cellPrefab) as CellMaze; cells[coordinates.x, coordinates.z] = newCell; newCell.coordinates = coordinates; newCell.name = "Maze Cell " + coordinates.x + ", " + coordinates.z; newCell.transform.parent = transform; newCell.transform.localPosition = new Vector3(coordinates.x - size.x * 0.5f + 0.5f, 0f, coordinates.z - size.z * 0.5f + 0.5f); return(newCell); }
private void CreateWall(CellMaze cell, CellMaze otherCell, DirectionMaze direction) { WallMaze wall = Instantiate(wallPrefab) as WallMaze; wall.Initialize(cell, otherCell, direction); if (otherCell != null) { wall = Instantiate(wallPrefab) as WallMaze; wall.Initialize(otherCell, cell, direction.GetOpposite()); } }