• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Authored Procedural Generation

  • Thread starter atxgamedesigner
  • Start date
A

atxgamedesigner

Guest
Im very interested in "authored" procedural generation - by this I mean having several pre-built sections of rooms, and then randomly place some of those pieces into the room that the player then interacts with.

I saw a theory video on youtube that mentions Spelunky specifically using a method like this.
Id love to know more about how this can be implemented.

Not looking to be spoonfed code - just looking to start a discussion on some higher level ideas on how this is achieved.

Thanks for your time!
 
Last edited by a moderator:
One way I have seen (not sure if spelunky does it this way) is to build maps off of sprites. Each pixel color in the sprite corresponds to an object/tile on the map. When the level loads, the code analyzes the sprite and builds out accordingly.

Then you just keep a bunch of sprites ready, it randomly chooses one and goes from there. I could even see using multiple sprites per level as layers - one sprite is base room layout (walls, doors), next sprite is objects/enemies spawn points.

So basically run through the sprite with something like: https://docs.yoyogames.com/source/dadiospice/002_reference/drawing/colour and blending/draw_getpixel_ext.html

Use that data to generate the map.

NOTE: I have never done this, just a theory at this point.
 
R

rui.rosario

Guest
You can generate a base layout (for example a grid representing connections from different cells) and have a pool of pre-built rooms. Then you just rotates and randomly pick rooms that fit the layout plugging them together. This is just a very generic overview, when I'm on my pc (currently on my cell) I'll post a more thorough explanation as well as other possibilities.
 

nesrocks

Member
The games Rogue Legacy and Dungeon of the Endless seem to also be done this way.
One simple approach could be to always have all rooms able to connect to one another, for example, the "door" is always exactly in the middle of the wall. You'd still need to manage which rooms have exits on each of the 4 sides (or closed walls), and build the map accordingly.

The game Dungeon of the Endless seem to use this "middle of the wall door" approach, but some rooms are "2 rooms wide" or "2 rooms tall".
 
R

rui.rosario

Guest
On my PC.

So as @nesrocks stated, this is done in quite some games. Without a particular idea of what type of game you were thinking of applying this in I can only give slight variations on the same technique (since it doesn't really vary that much when you have pre-built assets).

So the premise here is simple:
  • You have some well designed elements that you have pre-built
  • You want to pair them with either some procedurally generated content, or just glue them all together procedurally
Before I go any further, take note of The Three Hundred Project. It has a lot of ideas regarding procedural generation, some of which mention pre-fabricated assets. You can also Google a lot of things about procedural generation.

So, taking a Zelda-esque approach imagine you want a dungeon with lots of rooms to play around with. As I stated earlier, you might generate a layout procedurally (a grid with a bunch of abstract rooms represented by the connections to their neighbors). You now want to populate this dungeon. If you just want to use pre-built assets, then you will probably iterate through a few random assets, selecting the ones that fit the dungeon. This is one approach, but it gets boring quite fast since it is bound to get a lot repetitive. You can then maybe apply some transformation to the pre-built assets. Rotate them, mirror them and whatnot. This provides a bit more variety, but at its core it will still be repetitive, as well as in order to do this you probably have to stick to the centered door approach (as @nesrocks stated). One way you can further improve this is by subdividing each room into quarters. Now you have to layout your connections across ~4x the space and each room will be composed of 4 different pre-built assets. This also eliminates centered connections, since each room will have a maximum of two connections per side, but it will also have a maximum of 4 inner connections. If your pre-built assets are flexible, then you can apply a second pass to the dungeon and eliminate entire walls connecting internal parts of the room, so it looks more like an actual room. Maybe you can even apply this across rooms and have a really complex layout.
However, this is using strictly pre-built assets (although that last suggestion involved modifying them at runtime a bit). Yet, you can look at it from another spectrum: Your pre-built assets are just well tested puzzles or story-driven components, so you do not want to generate the entire dungeon from them, just feature some of them in it. This means you can procedurally generate both the layout and the actual contents. But instead of generating key story rooms or puzzles, you'd just plug a pre-built one instead (if pre-built assets are themable then it's even better, since the same puzzle can appear in two different dungeons, just that it shows up in one as a regular room and on another with the lava theme and mirrored on the x-axis).

Hopefully this example has given you enough slight variations on the subject so that you can start developing your own techniques for it.
EDIT: This is not even getting into some more advanced techniques, like noise-dependent generation and so forth.

If you need an actual example, I might whip something up upon a few days after your request.

Cheers,
Rui Rosário
 
A

atxgamedesigner

Guest
@DividingByZero - Thanks for your reply.
This sounds like an interesting approach, and I've seen a few other mentions of this method before.
My concern with this is speed.
The script would have to look at every pixel of a sprite and perform logic based on the value of that individual pixel...
This would absolutely work, and I've seen it on tutorials - but in a real application it just seems like it would come with some brutal load times.

@nesrocks - I have never heard of either of those games, I will check them out! Thanks for commenting.

@rui.rosario - I really appreciate the detailed response.
I'll check out The Three Hundred Project - I have not heard of that before.

It sounds like there is really no behind the scenes magic going on here - its just figuring out how I want to author these pieces ahead of time, and how I am going to go about using these pieces dynamically to create interesting rooms for the player to explore.

If anyone else would like to chime in on this, I would love to hear what you have to say!
Thank you!
 

nesrocks

Member
@atxgamedesigner I guess you don't need to check every pixel, just the border ones. Even so, it is only once at loading time (you build the map once every play). The delay wouldn't be too long.
 
@DividingByZero - Thanks for your reply.
This sounds like an interesting approach, and I've seen a few other mentions of this method before.
My concern with this is speed.
The script would have to look at every pixel of a sprite and perform logic based on the value of that individual pixel...
This would absolutely work, and I've seen it on tutorials - but in a real application it just seems like it would come with some brutal load times.
Yeah - I have heard the load times could be problematic. I guess it probably depends on how big your rooms are. The examples I have seen, the room sprites were something like 32x32 (maybe even smaller) - so it was relatively fast. But, with each increase in size, it would get more brutal. Maybe you could create some 'world generation' phases, so it isn't neccesarily happening during the room changes. Like, if you had a full dungeon, map the whole thing out from these sprites once at the beginning. So the first load might be long - but once in and changing rooms it would be fast.

Good luck! I'd love to hear what you come up with .
 
Top