I’m finally ready to share my first version of the Architect. The Architect is a Blueprint that handles the creation of all Blocks in the level. I’ll go over the logic behind creating rooms and then - well, there’s a problem I can’t figure out. No matter how many times I go over the logic, I can’t find the problem. I really hope someone else with a better sense of logic can help me find my mistake.
Good things first: most of the time, the Architect works and delivers beautiful random “Zelda” maps:
However, sometimes the logic bugs out and produces disconnected rooms. I have no idea why?!!?
The level you see is built from Blocks. Each Block is a Blueprint that contains a number of rooms as components. Every Block is predesigned by hand and the Architect gets all the Blocks fed and put into an array from which it selects what Block to place. So far so simple. In this example I have only one type of Block to better demonstrate the bug there currently is.
Now lets go over the logic behind the placement of those Blocks.
The whole placement of these Blocks comes in 3 steps. Setting a random rotation, finding a suitable location and lastly combining these two steps to produce a transform for the Block.
First step is a random rotation for the Block. Since it’s a Zelda map, these rotations are always in 90 degree angles.
If this is the first Block to create, I just want to place it wherever the Architect is placed in the map.
As said, the first Block will just be placed at the location of the Archtect. I then add the Block to my array that contains all locations of the created Blocks.
After the first Block is placed, we start looking for a new location for other Blocks. The Architect will continue looking until a new location has been found.
Here, I do 2 things. First, I determine a direction in which the new Block will spawn compared to the old one. Then, I pick a random Block that is already stored inside the array and break the X,Y and Z into variables.
Here, I check for the chosen direction. If the direction is north of the old Block, I add the size of a Block to the X. South subtracts the Blocksize from X. Same for East and West with the Y axis. Z stays untouched. Then I set this as the new Block position.
The Architect needs to check if the new location has already been used by another Block before. If it did, we do the whole Block finding logic again until the location has never been used before.
Now that the new location has been found, we add it to the array. I also added a few other arrays for debugging purposes.
The last step is putting the rotation and vector together to make the full transform for the new Block. I also reset the Block found variable, so after placing the Block, the process can start anew for the next Block.
I know this logic is pretty simple and it also produces disconnected Blocks - I can’t figure out why. If you have an idea, please let me know!
The next step: adding specials to Blocks - for example Blocks that are locked and require a key to access, a Block for the player start position to spawn, a Block for the exit and so on.
If you have any questions, let me know!