A C# algorithm to build interesting cave systems for your Roguelike – part 2 class layout
This article describes the layout of the class csCaveGenerator.cs which is used to generate a cave system, and can be viewed on GitHub here.?Within this class are several regions which are used to group together related methods, properties, data structures etc. These regions are:
- Properties
- Misc
- Map Structures
- Lookups
- Cave Related
- Corridor Related
- Direction Related
- Cell Related
Properties Region
Contains the properties used to control the appearance of the cave system being generated. Discussed in detail in part 1.
Misc
Contains the class constructor and the method Build() which generates the caves.
Map Structures Region
This contains the generic lists used to hold cave system data: Caves, Corridors and Map.
Lookups Region
Contains two lists of points which contain directions:
- Directions: four points which represent North, South, East and West.
- Directions1: 8 points which represent?North, South, East, West, North East, North West, South East and South West.
These lists are used to examine the neighbours of a cell for the cave generation, smoothing and filling operations.
Cave Related Region
Contains the code used to generate caves, and subdivided into three regions:
- Make Caves
- Locate Caves
- Connect Caves
Make Caves
This contains the method BuildCaves() which generates the cave system
Locate Caves
This contains three methods used to locate discrete caves on the map and place them in the generic list?Caves.?The method GetCaves() is called to do this - which uses a recursive flood fill algorithm.
Connect Caves
Contains the method?ConnectCaves(), a brute force method which randomly attempts to connect caves. Dependant upon methods in the Cave Related Region.
Corridor Related Region
Contains the methods:
- Corridor_GetEdge()
- Corridor_Attempt()
- Corridor_PointTest()
Which are all used by the method ConnectCaves().
Direction Related Region
This region contains a series of methods using in locating the neighbours of a cell, generating a randomly direction etc
Cell Related Region
A series of methods used for manipulating map cells.
Leave a comment