Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: BaJankens on Tue 12/04/2016 19:13:25

Title: [SOLVED] Is there a tutorial for procedural dungeons?
Post by: BaJankens on Tue 12/04/2016 19:13:25
I've been working on a project that might require procedural dungeons and was wondering if there was a tutorial or source code available to teach how to make something like that possible. I've been looking around and seeing a few games that utilize this, but can't find any how-to's on the matter. It won't be standard rogue-like ASCII style dungeon, but rather a more binding of isaac/room-by-room procedure. If you can shed any light on this, I'd very much appreciate it.
Title: Re: Is there a tutorial for procedural dungeons?
Post by: Khris on Tue 12/04/2016 23:21:11
First you need to start with an algorithm. Creating an Isaac-style map isn't too hard; the basic idea is to use a grid, say 20x10 cells, place a room near the center, then add a certain number of rooms randomly next to existing ones. The easiest way is to create two random numbers as coordinates, then check all four neighboring cells. If exactly one of them contains a room, add a room to the current cell. If not, create new coordinates.
Java example: http://ideone.com/Zw2dbS
Result:
                        []              
                      [][][][][]       
                      []               
                  []  [][][]           
              [][][][][]               
                []  []                 
                  [][][][]             
              [][][]    [][]           
                  [][]  []             
                    []                 
Next you need to place special rooms; you should have an algorithm that calculates the distance between two rooms (A*) so you can check chosen rooms for being not too close to each other (or whatever other conditions the level needs to fulfill).

Implementing the map in AGS is the next step. You can in theory use a single room for the entire maze, drawing exits and walls during the game.
Needless to say, you should have a good grasp of basic game programming, not just the AGS engine.
The player's current room is represented by her coordinates within the map grid; leaving the room to the right will simply increment x by one and load the adjacent map room into the AGS room (by redrawing the background, turning walkable areas on/off, etc.)
Title: Re: Is there a tutorial for procedural dungeons?
Post by: Retro Wolf on Wed 13/04/2016 14:00:11
You might find THIS MODULE (http://www.adventuregamestudio.co.uk/forums/index.php?topic=40952.0) interesting.
Title: Re: Is there a tutorial for procedural dungeons?
Post by: BaJankens on Thu 14/04/2016 06:21:15
Thanks for the advice. This helped point me in the right direction and I think I've figured enough out to get where I need to go! :grin::grin::grin:
Title: Re: [SOLVED] Is there a tutorial for procedural dungeons?
Post by: Monsieur OUXX on Thu 14/04/2016 10:28:15
Quote from: Retro Wolf on Wed 13/04/2016 14:00:11
You might find THIS MODULE (http://www.adventuregamestudio.co.uk/forums/index.php?topic=40952.0) interesting.

Just to explain to you how that post inserts in the discussion :
- Khris explained to you how to generate the maze, by using some randomness
- Retro Wolf provided a tool to generate "seeded randomness". that's a special kind of randomness where the sequences of random numbers generated will be the SAME every time provided you start out the sequence with the same initial number (seed).

That's helpful if you want to be able to generate the same maze twice amongst the millions of possible random mazes. For example, if you think of the game "worms", there were 65,000 available levels to play, but they were not actually stored on the disk. Instead, they were randomly generated, but each starting from one fixed seed (a number between 1 and 65,000).