void CreatePassage(MazeCellHexa currentCell, MazeCellHexa neighbor, MazeDirectionHexa direction) { MazePassageHexa passage = Instantiate(passagePrefabHexa) as MazePassageHexa; passage.Init(currentCell, neighbor, direction); passage = Instantiate(passagePrefabHexa) as MazePassageHexa; passage.Init(neighbor, currentCell, direction.GetOpposite()); }
void CreateWall(MazeCellHexa currentCell, MazeCellHexa neighbor, MazeDirectionHexa direction) { MazeWallHexa wall = Instantiate(wallPrefabHexa) as MazeWallHexa; wall.Init(currentCell, neighbor, direction); if (neighbor != null) { wall = Instantiate(wallPrefabHexa) as MazeWallHexa; wall.Init(neighbor, currentCell, direction.GetOpposite()); } }
public void Init(MazeCellHexa cell, MazeCellHexa other, MazeDirectionHexa direction) { this.cell = cell; this.other = other; this.direction = direction; cell.SetEdge(this, direction); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
MazeCellHexa CreateCell(Vector2 coord) { MazeCellHexa newCell = Instantiate(cellPrefabHexa) as MazeCellHexa; newCell.name = "Maze Cell " + coord.x + ", " + coord.y; newCell.transform.parent = transform; newCell.transform.position = new Vector3( coord.x, coord.y, 0f); newCell.coord = coord; cells.Add(newCell); return(newCell); }
void NextGenerationStep(List <MazeCellHexa> activeCells) { //Debug.Log("active cells count: " + activeCells.Count); int currentIndex = activeCells.Count - 1; MazeCellHexa currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { //Debug.Log("Fully initialized cell"); activeCells.RemoveAt(currentIndex); return; } MazeDirectionHexa direction = currentCell.RandomUninitializedDirection; Vector2 coord = currentCell.coord + direction.ToVector2(); if (ContainsHexa(coord) == true) { MazeCellHexa neighbor = GetCellHexa(coord); if (neighbor == null) { neighbor = CreateCell(coord); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (neighbor != null) { CreateWall(currentCell, neighbor, direction); } } else if (ContainsHexa(coord) == false) { CreateWall(currentCell, null, direction); } }