Problem with room generation

I want to create a room generation like in the image where there are rooms with various sizes (eg. 1x1 ; 2x1; 2x2) connected to each other. The problem is I don’t know how achieve this. I searched many websites to find a tutorial for that but it didn’t work.

Since you have perfect squares here, this is just a matter of removing key walls.

2 Likes

consider reverse engineering those random room generators that you can easily find on the toolbox.

if that is too complicated then make a simple room model, add a start and as many end nodes as you want, then in a seperate function find the last index and its end nodes, then position its start node at the end node.

@GnomeCode has a tutorial series on making a “doors-like” game. It covers room generation and randomization.

2 Likes

I’m sorry but I don’t understand what do you mean by that

I watched that earlier and it’s more about linear generation where each room is spawned one after one. My point is to make more like procedural room generation where many rooms are connected to each other.

It looks like your room generator is pretty straightforward. Seems like all you need is a wall remover.
Data could be 5,12,23,24,45,56 exc.. and it just removes the walls for that, counted top to bottom left to right. As you could start out with all walls and simply remove the ones you need to. Could even pre-make that, clone the whole thing to the workspace and just have a wall remover.. Maybe add a few things to a few rooms or change some colors. Should be pretty easy if your game map is all perfect square rooms like that.

Make a grid. Place your POIs on that grid. Pick a spot for the player to start. Generate a random path from the spawn to each POI, so that the path will create its own “directional map” of directions the player can move from one grid to another (i.e., up-down, left-right, a corner, a T-junction, a cross, a dead end). Fill out that map with room tiles that satisfy the direction map you generated.

Alternatively, if you need every point to be filled, you can loop over that same grid. For each point in the grid, store if that point is empty or filled (empty by default). Starting at the top, generate a random room. Check if that room shape is not overlapping an already filled tile. If it is, then generate a smaller room or skip the tile. Repeat until full.

You could probably look at the source code for something like SCP:CB to find out.

Just wondering if you’ve viewed this yet