Devlog 8: Corridor Generator Class
This week, the focus shifts to the CorridorGenerator class. While the Binary Space Partitioning (BSP) algorithm divides space into rooms, these rooms need to be connected so they can be travelled to. The CorridorGenerator class addresses this by generating corridors that link the child nodes of the RoomNode objects.
The CreateCorridors method within this class takes a list of all RoomNode objects (allSpaceNodes) and the desired width of the corridors (corridorWidth). It then processes each room node, prioritizing nodes with higher TreeLayerIndex values, which ensures that the parent nodes are processed first. By ordering the nodes in descending order, the method guarantees that corridors are created between the appropriate rooms, starting from the top-level parent nodes down to the lower-level child nodes.
Each room node is checked to see if it has any child nodes. If a room node has no children, it is skipped in the corridor creation process. If a room node has children, the method generates a CorridorNode, which represents a corridor connecting the first two child rooms in the list. The width of the corridor is determined by the corridorWidth parameter.
After the corridor is created, it is added to a list of corridors (corridorList). Once all nodes have been processed and all corridors have been generated, the method returns the list of corridors, which can then be used to visualize or further process the dungeon layout.
Reference List
Sunny Valley Studio. (2019). Unity 3d procedural dungeon generator. [YouTube playlist]. Available from: https://www.youtube.com/playlist?list=PLcRSafycjWFfEPbSSjGMNY-goOZTuBPMW [accessed 20 November 2024].