Dungeon arrangement / random generation

K

kaerpaenen

Guest
Is there a way of placing pre-made rooms inside of bigger rooms in Game Maker Studio 2?

Basically, I'm trying to figure out a way of making a random dungeon, Binding of Isaac -style, so I'd be making rooms by hand each in its "own room" in GMS2, and then loading/applying them into one bigger room tiling them. Is there any way to do this, or am I approaching this wrong? How can I create rooms and pick them randomly to use in a bigger map?
 

Fabseven

Member
( i am using gm1.4 atm so i am not sure my answer will be 100% accurate)
A simple way to make it could be :
I think you should, as you said, create your own room and name them something like room_premade_001 , room_premade_002 an so on...
Then, create a script named "room_random_selection"
in this script it's possible to create a ds_list and loop on rooms name room_premade_xxx and randomly ad them to the ds_list , the ds_list must be global or in a simpleton object (= obj_system for instance, and you only got one)

Then when you start the game, go into the first room of the ds_list,
when ending the first room, go to the second room of the ds_list, etc...
In the end you have in the editor , room_premade_001 , 002 , 003 ,004, 100
and in the end the player will encounter room 002 004 005 006 ... (for instance)
Finally it's only a begin to end room generator but still i hope it will helps you.

Try this and then make the thing grow,
It may be possible to create a second loop in room_random_selection to attribute room for each exit of the room but kind of hard given you wont /
access obj's room to know how much exit there are x)
Another idea : when entering room, run a script "give_room_to_exits" looping on each obj_exit and setupping obj_exit.room_id_to_go , delete the used room_id in your ds list while doing this (if you want)
Another idea : use a ds_grid instead of a ds_list and in room_random_selection , while reading a file to know the number of exit for each room, attribution of the exit for each room and "give_room_to_exits" will do the real assignation ( or obj_exit could read it's own exit in the ds_grid)
 

JackTurbo

Member
This is pretty much how my game A Day In Valhalla is handling dungeon generation.

Each room is a hand crafted game maker room. The level as a whole is simply a 2d array full of room IDs. My main control object has variables for currentRoomX and currentRoomY which is the array location for the current room.

If you exit rightwards for example the game simply adds 1 to the currentRoomX and loads the room at the updated array coords.

The actual generation comes at level start and is how that array get populated. There are a few guides floating around on different ways to approach that
 

NightFrost

Member
Binding of Isaac randomly generates its dungeon layouts. This falls under the general idea of procedural generation, using algorithms to create randomized content. I recall Isaac's layouts are relatively simple, since each room is the same size so the layout can be generated in a vaguely grid-like fashion. Handcrafted rooms likely don't exist as separate rooms at all, but as data. When you exit a room, in gamemaker terms you just stay in the same room; it gets wiped clean and contents of the new one are read from data structures and spawned accordingly. The game would contain a map editor dev tool to quickly edit these rooms.
 

Fabseven

Member
Maybe it's possible to use the Game maker room editor for your own. Try to design a room and to create a script reading obj and things in this room and writing them to a ini file or something else.
If working you could read theses files to load room as you like.
 

Simon Gust

Member
Maybe it's possible to use the Game maker room editor for your own. Try to design a room and to create a script reading obj and things in this room and writing them to a ini file or something else.
If working you could read theses files to load room as you like.
Or make an image in paint and have game maker interpret the colors as objects / tiles.
 
K

kaerpaenen

Guest
Thank you for so many replies, lots of stuff to think of! 2D array / ds_grid sound like a way to go for me, I think I'm going to try that. I read some more and it seems very viable solution! I'll just have to try and figure out the room transitions and repositioning the player in the correct place in the next room etc. etc.

Making image in paint and game maker reading from it sounds like a cool idea too, it would make designing rooms fairly simple and quick! Definitely going to look more into these. Thanks all!
 

sylvain_l

Member
if I understand that right
Or make an image in paint and have game maker interpret the colors as objects / tiles.
it has the disadvantage of requiring to learn by heart the colors <-> object/tile dictionary; if it's a dozen it's OK, if you have thousands.:eek:

not that the GM room editor is perfect; it has it flows too if you have already save a bunch of room as externals ini, and you update your tilesets/add, change objects etc; can lead to mismatching between version of ini files :(

@kaerpaenen
there are a bunch of function to create/maniulate room on the flie as to manipulate layers (current and also other rooms) so you could definitely do it. ( IDK the limitation, never try to work with those much)
 

NightFrost

Member
Or make an image in paint and have game maker interpret the colors as objects / tiles.
I've used this approach and it works relatively well. I had color codes for each of wall tile, treasure spawn spot and enemy spawn spot. each building block was a 16x16 pixel image, and there were several layouts for each exit arrangement (ie, five different layouts for a room that only has north exit). These sprites were processed and read into buffer at game start for fast retrieval when a room was generated. The biggest downside obviously was how every change needed to be done in image editor and then had to be imported to GMS. For more complex maps it probably is preferable to build a simple editor that exports a file (like JSON) and then read that into the game.
 
Top