Array-Based Room Generation

Right now I am dabbling with a few theoretical game maker projects and one thing that really piques my curiosity is array-based room generation. I intend to make a sort of dungeon-crawler game that has randomly generated maps that change every 7 hours of in-game time.

First I am interested in a script that when used at the beginning of the game, it automatically generates rooms on a 26 x 26 grid. So we have room1_1, room1_2, room1_3... room26_24, room26_25, room26_26.

And a script would detect based off which room the player came from and set the player on the next room.
Example: If I go to the north-most point on one room, the player should teleport to the next room on its south-most point.

But if a player tried to go north or east in room1_1, they would be blocked off.
room1_1 - room1_26 do not allow north movements
room1_1 - room26_1 do not allow west movements
room26_1 - room26_26 do not allow south movments
room1_26 - room26_26 do not allow east movements

If I have to manually make 676 rooms, that's fine but tedious. But I would be grateful if anyone has a decent idea on how to accomplish this. Thank you!
 
S

Sunfish

Guest
Rather than have all rooms be seperate, have just one room that changes its layout based on the "room" the player is in.

For example, if I'm in room1_1, it would have instances spawned in as soon as I've entered it. Once I've left room1_1 to another room like 1_2, just have the same room just populate with a different set of instances.

A good way to tackle this is to populate each room with specific objects beforehand with code, save it as an array, and then spawn them in when the player gets into one.
 
Sounds much more efficient. I would need to set up some kind of identity/variable system so that each room entered although they're randomly generated from the beginning of the game, they stay the same until the next generation cycle. Things like rocks, trees, tiles, etc will be in the same place. I'll definitely need to play with this idea and come up with a solid way to make such a game.

Thank you for your input!
 

TheouAegis

Member
You have your 2d Array or ds_grid of room layouts. The values saved there will be pointers to indexed room data saved in arrays/data structures elsewhere.

If you think about it, if you prefabbed rooms, you only need 9 rooms.

1 2 3
4 5 6
7 8 9

Each room is a template. So room 1 is blocked on top and left, 2 only on top, and so forth. You could then use a random generator to populate each room so it looks more unique. Your 2d array could hold the random seed used to randomize each room.
 

Xer0botXer0

Senpai
You can purchase my room gen method if you're interested,

It'll show you how to create rooms with code, link them together how ever you decide, something like

|#######
|#000###
|#0#0###
|#00000#
|#####0#

Where the 0s represent rooms, and # walls.
I created the code which was to be used for the outside game world, mines to be escevated and houses to be expanded.

If not I suppose I could just explain the concept to you.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Let me shamelessly plug my dungeon crawler engine here: https://yaru.itch.io/yals-basic-dungeon-crawler-engine
It uses arrays for the rooms layout, but also sprite-based creation of the rooms themselves, so you can basically draw new layouts in a sprite and they'll be added to the random lineup.

I'm definitely seconding using the same room, it saves you a lot of time synchronizing data when you move between different rooms... if everything is in one big room, you can just let stuff's state depend on whether the objects are still there or they're destroyed, saving a lot of work. The hard part is coming up with a system to define dungeon rooms, and then create them in the actual room.
(which my engine would take care of, wink wink :p)
 
Top