Jump to content


Photo

Roguelike generation


  • Please log in to reply
12 replies to this topic

#1 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 19 February 2012 - 01:35 AM

I'm looking to start a fairly simple Roguelike game, but I have no idea how to start the random generation. What would be the best method? I'm looking to have a dungeon that gets its levels generated as you get deeper. Also item dropping, enemy spawning, etc.
  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 19 February 2012 - 01:42 AM

IWell there's three main methods:

A) Pregenerated blocks: Make a bunch of "mini levels" that can be fit together like a jigsaw to form the whole. Perfect for action/roguelikes. Spelunky uses this.

B) Build the level entirely full of walls, then subtract away corridors and rooms with "destroyer" objects. Good for turn-based or diggin (terraria)

C) Build entire dungeon levels on a textpad and choose them randomly. Lots of work, but good for small levels.

Edited by greep, 19 February 2012 - 01:43 AM.

  • 0

#3 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 19 February 2012 - 01:44 AM

IWell there's three main methods:

A) Pregenerated blocks: Make a bunch of "mini levels" that can be fit together like a jigsaw to form the whole. Perfect for action/roguelikes. Spelunky uses this.

B) Build the level entirely full of walls, then subtract away corridors and rooms with "destroyer" objects. Good for turn-based or diggin (terraria)

C) Build entire dungeon levels on a textpad and choose them randomly. Lots of work, but good for small levels.


I like the sound of A. How do I go about doing that?
  • 0

#4 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 19 February 2012 - 01:49 AM

First divide your room into several sections, probably 36 or 25 (6 by 6 or 5 by 5)

Then, Divide your "room" into sections with a for loop, like so

122221
233332
233332
233332
233332
122221

As you can see, there are 3 types of "blocks" you will have to make. Corner blocks, side blocks, and center blocks. These have to be designed in such a way that the open spaces in one block will fit into another. Anyways, have to go for a bit like right now, so I'll be more thurough later.

You can also try other methods, but I like this the best.
  • 0

#5 falconfetus8

falconfetus8

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 19 February 2012 - 02:00 AM

I like the sound of A. How do I go about doing that?


Here's a little something I wrote (and abandoned) quite a while ago. It might be a bit hard to figure out what I'm doing(I was a very sloppy coder back then), but if you poke around you might be able to tell what I've done.

http://www.mediafire.com/?g66xcr3ehrcy0w9

You might get an error because a sound is missing, but that's not important :P
  • 0

#6 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 19 February 2012 - 02:44 AM

First divide your room into several sections, probably 36 or 25 (6 by 6 or 5 by 5)

Then, Divide your "room" into sections with a for loop, like so

122221
233332
233332
233332
233332
122221

As you can see, there are 3 types of "blocks" you will have to make. Corner blocks, side blocks, and center blocks. These have to be designed in such a way that the open spaces in one block will fit into another. Anyways, have to go for a bit like right now, so I'll be more thurough later.

You can also try other methods, but I like this the best.

Yes if you could explain more that would be great. I understand what you are saying so far. How big should the room be?
  • 0

#7 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 19 February 2012 - 08:28 AM

Room size should honestly be as big as you can get without lag if you're an action/rogue. In a turn based roguelike, where you'd be using grids and tiles rather than solid walls, I'd say anything bigger than 150x150 is too big.

As far as how to actually make the blocks, personally I use a notepad and fill it with letters, which, when loading it from the file, you get them turned into the walls. The notepad would look something like this:

wwEEww
wwEEww
wwEEEE
wwEEEE
wwEEww
wwEEww

Es are empty, ws are walls (actually, personally I just leave E as a space, but it shows up on the forum better here this way). This is a corridor that leaves to the right, an example of a (extremely small) left side block. Character processing is easier in C++ so I actually put it into a C++ program which spits out another textfile that I process in game maker. Kinda silly but it works for me. Anyways you get the idea?

Now if you only want to use 3 types, you will need to rotate the sides and corners, as an upper left corner will not have the same exits as an upper right. To do this, process the file first, giving you a grid in game, then manipulate that grid with code. You'll have to make a dummy grid I think and then base the actual grid to be rotated on that dummy.

You will need about 10-30 of each type mind you, or else the dungeon will not look unique. So seriously consider method B unless you don't mind designing lots of the things.

Edited by greep, 19 February 2012 - 08:31 AM.

  • 0

#8 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 19 February 2012 - 09:47 AM

Apart from the methods outlined above there is all the BSP (Binary Space Partition) tree method. Basically it works like this... You take a room, and divide it in two (but NOT exactly equal... a bit more/less), then you divide each of those sections in two (again, NOT exactly half and half) and then again, and again etc... Until you have a series of spaces of different sizes. These spaces are "rooms" within the area, and all you have to do is wall them off and thenm create doors between them. It's a REALLY good method for producing rogue-like areas and something I toyed with a while back. You can see what I came up with here (read the whole topic as there are some interesting things) :

http://gmc.yoyogames...howtopic=489511

Now, I think I coded that a bit more coplicated than it actually needed to be, mainly because I wanted corridors to link the rooms with spaces between them. Hope that helps!
  • 0

#9 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 19 February 2012 - 10:08 PM

The other thing to consider, is using a combination method. E.g. Nocturnes method looks great and very playable, but it isn't terribly varied: you got decently sized block rooms and corridors and that's it. So you could use 50% of your rooms with nocturnes, and 50% with another method. I know DC:stone soup has about dozens of different level types. They also do something called "vaults (not the level Vaults)" which is to basically make a block that is rarely used but very special.
  • 0

#10 gangstar59

gangstar59

    GMC Member

  • GMC Member
  • 110 posts

Posted 19 February 2012 - 11:16 PM

everybody inspired binding of isaac :)
  • 0

#11 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 19 February 2012 - 11:40 PM

everybody inspired binding of isaac :)


Hah... okay I know it's funny that sex has always gotten higher maturity ratings than violence. But ages 16+ because of parodying religion? IN GERMANY?! This... this breaks the record for irony.

Edited by greep, 19 February 2012 - 11:40 PM.

  • 0

#12 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 20 February 2012 - 02:36 AM

Room size should honestly be as big as you can get without lag if you're an action/rogue. In a turn based roguelike, where you'd be using grids and tiles rather than solid walls, I'd say anything bigger than 150x150 is too big.

As far as how to actually make the blocks, personally I use a notepad and fill it with letters, which, when loading it from the file, you get them turned into the walls. The notepad would look something like this:

wwEEww
wwEEww
wwEEEE
wwEEEE
wwEEww
wwEEww

Es are empty, ws are walls (actually, personally I just leave E as a space, but it shows up on the forum better here this way). This is a corridor that leaves to the right, an example of a (extremely small) left side block. Character processing is easier in C++ so I actually put it into a C++ program which spits out another textfile that I process in game maker. Kinda silly but it works for me. Anyways you get the idea?

Now if you only want to use 3 types, you will need to rotate the sides and corners, as an upper left corner will not have the same exits as an upper right. To do this, process the file first, giving you a grid in game, then manipulate that grid with code. You'll have to make a dummy grid I think and then base the actual grid to be rotated on that dummy.

You will need about 10-30 of each type mind you, or else the dungeon will not look unique. So seriously consider method B unless you don't mind designing lots of the things.

I appreciate the explanation, but after reading the options again I like option B.
Can you explain a little on that?
  • 0

#13 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 20 February 2012 - 02:45 AM

Now I've never actually done this, so this is just the general idea. However, there are LOADS of scripts on the internet (mostly C++ but very transferable) that can describe this better.

Well basically, you first fill the entire room with walls, like a for loop. Then you make two random numbers determine to how many corridors and rooms you will make.

Then, starting at the center, you start making corridor_builders. These objects will upon creation will turn walls into empty space from their location out a few blocks in a certain direction. Further corridor builders will choose a random empty space, check if there is too much empty space in the area (i.e. corridor spam, too close to edge of room), and then do the same. Until you run out of corridors.

Then you make rooms. You take a random empty space, move out in one direction, check if it's a wall. If so, good. Move another in the same direction, check if a wall, if so good. Then it will choose a random size and go out in the direction it started, and see if it can make a rectangular room based on if all walls in the (area + 1) are in fact walls and not empty. If so, it creates the room and the door (at the very first wall check), otherwise starts over at choosing a random empty space. Note, the rooms should be highly variable in possible size, like 2x2 to 10x10.

Edited by greep, 20 February 2012 - 02:48 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users