Game Development Update
This was step one in dungeon generation
So when starting out Ethan and I knew we wanted a procedural generated dungeon so that players would be able to replay and have a different experience every time. This led to me trying to learn how to create a procedural dungeon within unity which I had never done before.
public class CorridorFirstGenerator : SimpleRandomWalkDungeonGenerator
{
[SerializeField]
private int corridorLength =14, corridorCount = 5;
[SerializeField]
[Range(0.1f, 1)]
private float roomPercent = 0.8f;
protected override void RunProceduralGeneration()
{
CorridorFirstGeneration();
}
private void CorridorFirstGeneration()
{
HashSet<Vector2Int> floorPositions = new HashSet<Vector2Int>();
HashSet<Vector2Int> potentialRoomPositions = new HashSet<Vector2Int>();
List<List<Vector2Int>> corridors = CreateCorridors(floorPositions, potentialRoomPositions);
HashSet<Vector2Int> roomPositions = CreateRooms(potentialRoomPositions);
List<Vector2Int> deadEnds = FindAllDeadEnds(floorPositions);
CreateRoomsAtDeadEnd(deadEnds, roomPositions);
floorPositions.UnionWith(roomPositions);
for(int i = 0; i < corridors.Count; i++)
{
// corridors[i] = IncreaseCorridorSizeByOne(corridors[i]);
corridors[i] = IncreaseCorridorBrush3by3(corridors[i]);
floorPositions.UnionWith(corridors[i]);
}
tilemapVisualizer.PaintFloorTiles(floorPositions);
WallGenerator.CreateWalls(floorPositions, tilemapVisualizer);
}
}
These were the first few methods that I wrote to make the dungeon generate all of the corridors first before storing the vectors that it ends at to generate rooms at the ends of corridors to create a complete map that if fully connected.
As you can see most of the variables are also serizalized so they can me modified in the unity editor so the dungeon is fully customizeable. My next step is to implement a way for objects to spawn in the rooms so that they aren’t empty.
Here is a gif that shows what the dungeon will look like when you click generate.