Open kmamal opened 7 years ago
I am going to use ASCII graphics to visualize dungeons. This is the current state of dungeons:
E--#--#--#
| | | |
#--#--#--#
| | | |
#--#--#--#
| | | |
#--#--B--#
E = Entrance B = Boss # = Room | and -- = Corridors
Right now the entrance is always at 0,0 and the boss room in the third place of the last row.
As a first step we should implement a simple maze algorithm:
Any room in the first row can be the Entrance. Any room in the last row can be the Boss. Some examples:
#--#--E--# #--#--#--E
| | | | | | | |
#--#--#--# #--#--#--#
| | | | | | | |
#--#--#--# #--#--#--#
| | | | | | | |
#--#--#--B B--#--#--#
In the current implementation all neighboring rooms are connected with one another by default. It should be the other way around: No room connects to any other room, unless there is a corridor between them. This is what such a dungeon would look like:
# # E #
# # # #
# # # #
# # # B
Use whatever data structure you prefer to store corridors. As an initial exercise, try to reconnect all neighboring rooms with each other using corridors, so you have the initial fully connected grid.
This is the most difficult step. Most maze generation algorithms require knowledge of Graph Algorithms which we have not dealt with yet. Here is an initial simple algorithm:
v
# # E #
2. Select a random room in the second row (marked X):
v
X # # #
3. Connect rooms in the first row until you are directly above the room of the second row:
v
X # # #
4. Connect the two rooms vertically:
|
X # # #
5. Repeat until you have reached the last row:
|
|
|
^
6. If the room that was randomly selected for the last row isn't the boss room, connect it with the boss room:
|
|
|
^
This should be enough for a start.
Current Behavior:
The dungeon is a grid. All rooms are connected with their neighbors in the 4 cardinal directions. It is impossible to choose a wrong path, or encounter a dead-end.
Desired behavior:
The dungeon should look more like an actual maze. Desired features include: