The way my dungeon generation currently works, is that there's a 4x3 grid of rooms that are randomly generated.
First the paths leading to/from the rooms are somewhat randomly generated, then rooms that are not fully connected are fixed, and then the tiles are placed.
For the most part, this works great. However, every now and then (probably every ~2% of the time), some rooms will be secluded, and inaccessable
without walking through walls. The way it's coded, it will never be just one room; it's always at least 2.
This becomes a problem, since the stairs down to the next level may spawn in this secluded area, preventing any further progress for the player.
Now that we've established the problem, here's my code for generating paths.
For each room, this script is run once.
hallN = irandom(1)
hallE = irandom(1)
hallS = irandom(1)
hallW = irandom(1)
if hallN = 0 && hallE = 0 && hallS = 0 && hallW = 0
{
if y != 0
{
hallN = 1
}
if x != room_width - 192
{
hallE = 1
}
if y != room_height - 192
{
hallS = 1
}
if x != 0
{
hallW = 1
}
}
if y = 0
{
if hallN = 1
{
hallN = 0
hallS = 1
}
}
if x = room_width - 192
{
if hallE = 1
{
hallE = 0
hallW = 1
}
}
if y = room_height - 192
{
if hallS = 1
{
hallS = 0
hallN = 1
}
}
if x = 0
{
if hallW = 1
{
hallW = 0
hallE = 1
}
}
//Top Left
if x = 0 && y = 0
{
if hallS = 0 && hallE = 0
{
hallS = 1
hallE = 1
}
}
//Top Right
if x = room_width - 192 && y = 0
{
if hallS = 0 && hallW = 0
{
hallS = 1
hallW = 1
}
}
//Bottom Left
if x = 0 && y = room_height - 192
{
if hallN = 0 && hallE = 0
{
hallN = 1
hallE = 1
}
}
//Bottom Right
if x = room_width - 192 && y = room_height - 192
{
if hallN = 0 && hallW = 0
{
hallN = 1
hallW = 1
}
}
//Left Mid
if x = 0 && y != 0 && y != room_height - 192
{
if hallN = 0 && hallE = 0 && hallS = 0
{
h = irandom(2)
if h = 0
{
hallN = 1
}
if h = 1
{
hallE = 1
}
if h = 2
{
hallS = 1
}
}
}
//Right Mid
if x = room_width - 192 && y != 0 && y != room_height - 192
{
if hallN = 0 && hallW = 0 && hallS = 0
{
h = irandom(2)
if h = 0
{
hallN = 1
}
if h = 1
{
hallW = 1
}
if h = 2
{
hallS = 1
}
}
}
//Top Mid
if y = 0 && x != 0 && x != room_width - 192
{
if hallE = 0 && hallW = 0 && hallS = 0
{
h = irandom(2)
if h = 0
{
hallE = 1
}
if h = 1
{
hallW = 1
}
if h = 2
{
hallS = 1
}
}
}
//Bottom Mid
if y = room_height - 192 && x != 0 && x != room_width - 192
{
if hallE = 0 && hallW = 0 && hallN = 0
{
h = irandom(2)
if h = 0
{
hallE = 1
}
if h = 1
{
hallW = 1
}
if h = 2
{
hallN = 1
}
}
}
global.hallN[x/192,y/192] = hallN
global.hallE[x/192,y/192] = hallE
global.hallS[x/192,y/192] = hallS
global.hallW[x/192,y/192] = hallWAnd then an alarm one step later runs this code:
if y != 0
{
if global.hallS[x/192,(y/192) - 1] = 1
{
hallN = 1
}
}
if x != 0
{
if global.hallE[x/192 - 1,(y/192)] = 1
{
hallW = 1
}
}
if y != room_height - 192
{
if global.hallN[x/192,(y/192) + 1] = 1
{
hallS = 1
}
}
if x != room_width - 192
{
if global.hallW[x/192 + 1,(y/192)] = 1
{
hallE = 1
}
}
global.hallN[x/192,y/192] = hallN
global.hallE[x/192,y/192] = hallE
global.hallS[x/192,y/192] = hallS
global.hallW[x/192,y/192] = hallWThe actual tile placement comes right after this, and tiles once placed cannot be removed or replaced.
So this means the solution has to come at some point between the script and the alarm.
I'm kinda lost here, so any suggestions would be helpful.



This topic is locked







