

Next, we check one of the already placed slots, and look for empty adjacent slots.

If position is available/EMPTY = 0, place new Room I pick a random adjacent empty slot, and check if position is available. Pick a random or fixed starting position, and create our first Room. I initialize the grid with desired With and Height. How i generate the level right now is illustrated in the following images:Īnd starting from step 4, is what i want to add. The dark slots are empty = 0Īs of now, i can only create a level with room sizes 1x1 = slot.īut i occasionally want to create larger rooms. Therefore i made some images, illustrating what i want, and what i currently have. Thank you for the reply! And i probably should have illustrated what i meant! Keep in mind that visual representation and the data behind the rooms are two different things and you can always design it in such a way to make one fit the other if that's something you need. With some customization this may go in the direction of what you are looking for?

While i probably would separate the rooms using math, not an actual physics simulation, it looks quite impressive: Or you can do it like this guy, who generated a ton of random rooms, separates them using collisions, then selects fitting rooms, connects them through a minimal spanning tree and calculated and generates paths to connect these rooms. Or you could place a desired number of rooms onto the grid (using something like a simplified Poisson Disc Sampling algorithm) and decide later which rooms should be connected. You could first generate the room hierarchy as a tree structure and then visualize it on a grid. You can also approach these kind of problems from different angles.
#Dungeon generator algorithm how to
There are also a lot of neat solutions for things like dungeon generators that may be worth looking into, and be it only to get inspired (or ideas for how to approach the problem). Generally speaking, when talking about procedural generation, it is often worth looking into some key topics like perlin noise or graph theory. If not, it may help if you visualized the desired result in some way and explained the data structure you intend to use. Your main problem is now that you need to figure out what size of room, if any, fits next to some other room in some direction on the array? If i understood you correctly, you plan on building your dungeon kind of like a tree, where each room knows the rooms it is connected to (hence the direction?). Rooms can be placed in such a way that they dont overlap with other, already placed, rooms. You have a grid (of bools?) and want to place rooms on it. I'm not sure i understood you correctly, so let me summarize: Or if it cannot "grow" any bigger, leave it as it is. If bigger than 1x1, it checks its surrounding slots, and continues to "grow" until size is reached. I also came up with the idea, when a room is placed, it randomly determines its own size Just to clarify, i am NOT asking for a script, merely a suggestion or push in the right direction (hehe) So my question, do you have any idea how this is made possible and easier then i just tried to explain? This should work, however its probably not as optimized as it should be. With this int, i'll check the length of both axes (is that the plural noun of axis?)Īnd select a random room size which will fit on/in our chosen spot/area. In the end, i'll return an int with the desired width and height. Thats a lot of writing the same for loops, but with different values. Until i have a selection consisting of only empty slots. However! Each time i encounter an occupied slot, i'll have to narrow the search, decreasing one of the axis.
