Jump to content


Photo

[SOLVED] Issue with procedural map generation


  • Please log in to reply
3 replies to this topic

#1 this_is_phil

this_is_phil

    GMC Member

  • GMC Member
  • 2 posts

Posted 11 July 2012 - 12:29 PM

I am trying to create a procedural map of a dungeon. The map is stored in a global 2D array. My issue seems to be when I start creating rooms after the first one. The process I'm trying to follow is as follows:

  • Find a random location in the map and create a rectangular room.
  • Search random locations until you find a wall
  • Check that a new room will fit in the designated area
  • Dig the new room
  • Repeat steps 2 to 4 until maximum number of rooms reached or no viable spaces can be found

The issues seems to be somewhere in the middle 3 steps. As I have no idea where the problem come from I will provide complete listing of the scripts I use.

Spoiler


Spoiler


Spoiler


The remainder of the program simply writes the result to a text file just so I can see if it works. The issue is that all that happens is the first room is created. Following on from that there is nothing.

Thanks to anyone who can help. I apologise if the solution turns out to be really simple I recently overhauled all of this code because I discovered that GML does handle arrays like most programming languages and they cannot be passed as arguments or returned from functions.

Edited by this_is_phil, 12 July 2012 - 03:09 PM.

  • 0

#2 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 12 July 2012 - 12:52 AM

For starters, try declaring all of local variables with var (in all of three scripts) to see if it fixes problem.
var width, height, seed, rooms, i, j, selected, pos_x, pos_y, w, h, ...;
It is especially important for loop counters like i and j. If you don't declare variables, they become instance variables of self, ending up in overwriting the same variable each other.
  • 1

#3 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3276 posts
  • Version:GM8.1

Posted 12 July 2012 - 03:00 AM

randomly choosing room sizes, randomly placing them and checking if they fit ain't such a great system. i guess dividing your entire map in half, diving each section in half and every section after is a faster, easier way of creating dungeon maps.
Posted Image
  • 1

#4 this_is_phil

this_is_phil

    GMC Member

  • GMC Member
  • 2 posts

Posted 12 July 2012 - 03:21 PM

Thanks for the suggestions, I found that the error was in checking the contents of each cell, instead of using logical or in the if statements I nested them.

@slayer 64: I know there are easier ways of randomly generating maps but the idea for this method is that it is like building a dungeon in Dungeon Keeper. You start out by building the first room and then dig other rooms and corridors off that. The aim is to create a more realistically built dungeon.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users