Where to start with procedural map generation.


  • Posts: 79
First I apologize if this has been covered, I did look around the forums but couldn't quite identify with any of the topics I came upon while searching.

I have illustrated my question, but I'll follow up with text as well: Hopefully I make sense. :)

Basically, I want to create a side scroller dungeon that builds itself off a fixed starting room and uses pre built scenes as rooms inside the dungeon..  The problem is that I'm not sure where to begin,. I'm not sure if this is a behavior or arbitrary code, if it needs to be attached to a scene (like the starter room) or not.

If I'm not clear enough I am sorry,  if any one has any ideas where to start, I'd be very appreciative. If I need to clarify something please let me know as well.

Thanks so much.

imagine gaming

  • Posts: 99
If I'm understanding correctly, I would go about this by using random numbers.

Say we have 11 scenes, one being the starting scene, which is always the same.
Assign each scene with a number;
Starting scene = 0
Scene 1 = 1
Scene 2 = 2
Scene 3 = 3
Scene 4 = 4 and so on down to 10.

We will also need a number attribute, we'll call it scene number.

Once the player completes the initial scene, create a [set scene number to ( random number between 1 and 10)] we don't want 0 because that's the starting scene.

Then create an event that checks what scene number equals, for example if it equals 4, load scene 4.

I hope I explained myself well, and this is what you indeed want.

« Last Edit: December 18, 2014, 01:41:50 pm by imagine gaming »


  • *
  • Posts: 4643
Hey, this is crazy close to what I'm doing with the Metroid Generator; how exciting!

I'm doing mine in code mode, but it would be entirely possible for it to be done with blocks as well. A few thoughts come to mind;

0. To answer your question; putting it in a starter scene is fine if you're going to do some generation there. My plan is to generate on a "new game" trigger; perhaps with options to tweak the settings while doing so if desired.

1. Since each room is a pre-built scene, if you don't need a dungeon map then you can send the player to any of your pre-built rooms any time they go through a door. If you want it to feel logical, then just make sure you have every door save which scene it should be going to (presumably with game attributes, so the data doesn't get lost on scene switch). If you want it a bit more maze-like, then you could just go to a random room every time or at least some of the time.

2. If you do need a map, or at least the ability to have the rooms fit into your grid (as in the example), you could do something like what I am doing. In my case, I create rooms based on a 2D grid (a list of lists) by having an algorithm make one after the other in a chain with some checking to make sure they don't overlap.
There are lots of examples of things like this online; the bottom of this ProcJam post has quite a few links to get you started.

Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.


  • Posts: 79
Thanks both of you.. i'm taking this in.. but to answer some aesthetic questions..

Yeah.. the dungeon should be logical.. not random, but procedural. So it doesn't drop a hundred item rooms and a boss room and thats it..

I'm not sure on the map yet.. but I am thinking I would like to be able to save the seed that is generated from a particular run if players want to share a certain run through.

This will be a rogue-like tho, so the saving aspect will be limited to general things.. not particular save games.

Thanks for the feedback!


  • Posts: 79
Also.. Imagine Gaming, your random.stencyl doesn't seem to run when I import it. I might be doing something wrong tho..