GMS 2 [HELP] Create a dungeon with premade rooms

Discussion in 'Programming' started by RedP, Aug 13, 2019 at 6:50 PM.

  1. RedP

    RedP Member

    Joined:
    Apr 8, 2017
    Posts:
    35
    Hi, i'm trying to create random dungeons with premade rooms, i created a ds_grid with the total of rooms that can be generated, but i don't understand how can i set where each room need to be placed in the grid. I feel completly lost, already read a few tutorials and gamamaker docs, but can't figure out how to actually code it, if someone at least give me some light and the process to make it work would help so much.

    Thank you!!
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,857
    The basic idea in Spelunky-style dungeons is having a number of prefabricated room templates stored in some manner. Imagine for example a 11x11 cell grid. At its simplest, you would set each grid cell either to zero to indicate an empty tile, or to one to indicate a wall tile. When a prefab piece is used to build a dungeon, the constructor would loop through every cell and set a wall pieces at designated spots. The steps inside the room would depend on your tile sprite sizes. If it were 32x32 pixels, the constructor loop would step the creation location 32 pixels every time it jumps to next grid cell.

    To construct an entire dungeon of these prefab pieces, you'd first initialize another grid. Then you'd fill it with IDs of the prefab pieces, either completely randomly or according to some algorithm. After that loop through the grid, fetch the prefab piece data and construct the dungeon piece by piece as explained above. Important thing is to construct your prefab pieces according to some guideline so they all fit together at the edges.

    One method I've used for this is maze generation algorithms. It would first create a maze on for example a 8x8 grid, and then I would pick suitable prefab room based on where the exits on each maze cell lie.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice