private void CreateRooms() { var roomsList = ProceduralGenerationAlgorithms.BinarySpacePartitioning(new BoundsInt((Vector3Int)startPosition, new Vector3Int(dungeonWidth, dungeonHeight, 0)), minRoomWidth, minRoomHeight); HashSet <Vector2Int> floor = new HashSet <Vector2Int>(); if (randomWalkRooms) { floor = CreateRoomsRandomly(roomsList); } else { floor = CreateSimpleRooms(roomsList); } List <Vector2Int> roomCenters = new List <Vector2Int>(); foreach (var room in roomsList) { roomCenters.Add((Vector2Int)Vector3Int.RoundToInt(room.center)); } HashSet <Vector2Int> corridors = ConnectRooms(roomCenters); floor.UnionWith(corridors); tilemapVisualizer.PaintFloorTiles(floor); WallGenerator.CreateWalls(floor, tilemapVisualizer); }
private void CreateRooms() { var roomsList = ProceduralGenerationAlgorithms.BinarySpacePartitioning(new BoundsInt((Vector3Int)startPos, new Vector3Int(dungeonWidth, dungeonHeight, 0)), minRoomWidth, minRoomHeight); // divide the dungeon into multiple rooms HashSet <Vector2Int> floor = new HashSet <Vector2Int>(); if (randomWalkRooms) { floor = CreateRoomsRandomly(roomsList); // create rooms with randomwalk using the divided rooms provided } else { floor = CreateSimpleRooms(roomsList); // create simple rooms using the divided rooms provided } List <Vector2Int> roomCenters = new List <Vector2Int>(); foreach (var room in roomsList) { roomCenters.Add((Vector2Int)Vector3Int.RoundToInt(room.center)); // get the center of each room and add it to roomCenters } HashSet <Vector2Int> corridors = ConnectRooms(roomCenters); floor.UnionWith(corridors); tilemapVisualizer.PaintFloorTile(floor); WallGenerator.CreateWall(floor, tilemapVisualizer); }
private void CreateCorridors(HashSet <Vector2Int> floorPositions, HashSet <Vector2Int> potentialRoomPositions) { var currentPosition = startPosition; potentialRoomPositions.Add(currentPosition); for (int i = 0; i < corridorCount; i++) { var corridor = ProceduralGenerationAlgorithms.RandomWalkCorridor(currentPosition, corridorLength); currentPosition = corridor[corridor.Count - 1]; potentialRoomPositions.Add(currentPosition); floorPositions.UnionWith(corridor); } }
private void CreateCorridoor(HashSet <Vector2Int> floorPositions, HashSet <Vector2Int> potentialRoomPositions) { var currentPos = startPos; potentialRoomPositions.Add(currentPos); for (int i = 0; i < corridorCount; i++) { var corridor = ProceduralGenerationAlgorithms.RandomWalkCorridor(currentPos, corridorLength); currentPos = corridor[corridor.Count - 1]; // make sure the start pos of new corridor link to the end pos of the previous corridor potentialRoomPositions.Add(currentPos); // adding end/start pos of each corridor as potential room pos floorPositions.UnionWith(corridor); } }
protected HashSet <Vector2Int> RunRandomWalk(SimpleRandomWalk_SO parameters, Vector2Int pos) { var currentPos = pos; HashSet <Vector2Int> floorPositions = new HashSet <Vector2Int>(); for (int i = 0; i < parameters.iterations; i++) // creating iteration amount of path (random walk) { var path = ProceduralGenerationAlgorithms.SimpleRandomWalk(currentPos, parameters.walkLength); floorPositions.UnionWith(path); if (parameters.startRandomlyEachIteration) { currentPos = floorPositions.ElementAt(UnityEngine.Random.Range(0, floorPositions.Count)); // set the start pos to a random floor pos } } return(floorPositions); }
protected HashSet <Vector2Int> RunRandomWalk(SimpleRandomWalkSO parameters, Vector2Int position) { var currentPosition = position; HashSet <Vector2Int> floorPositions = new HashSet <Vector2Int>(); for (int i = 0; i < parameters.iterations; i++) { var path = ProceduralGenerationAlgorithms.SimpleRandomWalk(currentPosition, parameters.walkLength); floorPositions.UnionWith(path); if (parameters.startRandomlyEachIteration) { currentPosition = floorPositions.ElementAt(Random.Range(0, floorPositions.Count)); } } return(floorPositions); }