private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; Vector2i coordinates = currentCell.coordinates + direction.ToVector2i(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } else { if (playerStartCreated) { CreateWall(currentCell, null, direction); } else { CreateWall(currentCell, null, direction); GameObject start = GameObject.Instantiate(playerStartPrefab) as GameObject; start.transform.parent = transform; start.transform.localPosition = new Vector3( coordinates.x - size.x * 0.5f + 0.5f - direction.ToVector2i().x, transform.position.y + start.transform.localPosition.y, coordinates.z - size.z * 0.5f + 0.5f - direction.ToVector2i().z); playerStartCreated = true; playerStartCell = currentCell; playerStartCell.RegisterEntity(); } } }
private void PlaceExitDoor() { while (true) { MazeCell rcell = cells[Random.Range(0, size.x), Random.Range(0, size.z)]; for (int i = 0; i < MazeDirections.Count; i++) { MazeDirection dir = MazeDirection.North + i; MazeCellEdge edge = rcell.GetEdge(dir); if (edge is MazeWall) { rcell.DestroyEdge(dir); Vector2i coordinates = rcell.coordinates + dir.ToVector2i(); if (ContainsCoordinates(coordinates)) { exitDoor = CreateChangeStageDoor(rcell, GetCell(coordinates), dir, 1); } else { exitDoor = CreateChangeStageDoor(rcell, null, dir, 1); } return; } } } }
private void CheckWallside(MazeCell cell, MazeDirection dir, int delta) { if (cell.GetEdge(dir + delta) is MazeWall) { if (closedTurnWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(closedTurnWallDecorPrefab, dir, delta); } return; } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i())) { MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i()); if (otherCell.GetEdge(dir - delta) is MazeWall) { if (openTurnWallDecorPrefab != null) { if (!cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(openTurnWallDecorPrefab, dir, delta); } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i())) { MazeCell sideCell = GetCell(cell.coordinates + (dir + delta).ToVector2i()); if (!sideCell.IsCornerInitialized(dir, -delta)) { sideCell.InitializeCorner(openTurnWallDecorPrefab, dir, -delta); } } } return; } } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i())) { MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i()); if (otherCell.GetEdge(dir) is MazeWall) { if (straightWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(straightWallDecorPrefab, dir, delta); } return; } } }