Random dungeon generation tinykeep3/20/2023 For the next stage we want to link each room together. The remaining cells are still useful however. Because of the Park-Miller Normal Distribution described earlier, there will only be a small amount of rooms in comparison to the number of cells, with lots of space between. We determine which of the cells in the grid are rooms - any cell with a width and height above a certain threshold is made into a room. The result is that we end up with a square grid of differently sized cells, all perfectly packed together.ĥ. We fill in any gaps with 1x1 sized cells. ![]() This technique ensures that the cells are not overlapping, yet in general remain as tightly packed together as possible.Ĥ. Next we use simple separation steering behaviour to separate out all of the rectangles so that none are overlapping. At this point we have 150 random cells in a small area, most are overlapping. In addition to this I ensure that the ratio between the width and length of each cell is not too large, we don't want perfectly square rooms but neither do we want really skinny ones, but somewhere in between.ģ. The reason for this will be explained later! This skews the size of the cells so that they are more likely to be of a small size (more smaller cells, less larger cells). Instead of using uniformly distributed random numbers (the default Math.random generator in most languages), I'm using Park-Miller Normal Distribution. Again the radius doesn't matter too much, but it should probably be proportionate to the number of cells. For each "cell" I spawn a Rectangle of random width and length within some radius. This is an arbitrary amount really, but the higher the number the larger the dungeon and in general more complexity.Ģ. First I set the number of cells I want to generate, say 150. It's pretty over-engineered, but hopefully will give anyone who is interested some ideas on generating dungeon layouts for their own games.ġ. Today I'm going to talk about one technical aspect of the game, that is random procedural dungeon generation. Hopefully this will somewhat pay for the sin I am about to commit at the end of the post. If there is also a collision, then it seems impossible to connect this room and you might have to place it somewhere else or prune it.Īnother approach would be to avoid such situations in the first place by modifying your room generation algorithm in a way that neighboring rooms will always have overlapping edges.I was originally going to advertise my Kickstarter project TinyKeep here, but as everyone knows spamming a message board is not good etiquette so I thought I'd share some knowledge with the community as well. If it is possible, then try one direction and check if there is a collision with another room. I am not sure how exactly you calculate your minimum spanning tree, but I find it very likely that it is actually impossible to intersect another room that way. The safest solution would be to draw the L-shaped corridor between the closest corners. ![]() ![]() But that might result in these two corridors intersecting a third, unrelated room (like room 0 in this example). ![]() Now you could pick a random point on the x edge of one and the y edge on the other and then draw two corridors extending from those points until they meet. Here you need an L-shaped connecting wall. The only rooms where that wouldn't work in your example are rooms 8 and 9, because they have no overlap on either axis. The code for generating the horizontal connections would look the same, just with the x-axis and y-axis reversed. GeneratePathway(pathPosX, room1.y1, pathPosX, room2.y2) GeneratePathway(pathPosX, room1.y2, pathPosX, room2.y1) check which two y-walls are the two closest ones The code for the vertical connections would look something like this: // calculate x overlap rangeįloat rangeXfrom = Mathf.max(room1.x1, room2.x1) įloat rangeXto = Mathf.min(room1.x2, room2.x2) įloat pathPosX = Random.Range(rangeXfrom, rangeXto) When the two rooms you want to link have overlap on the x-axis or y-axis, then it is a rather trivial case: Calculate the overlap range and generate a corridor at a random coordinate on that overlap.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |