Jump to content


Mr Weird Guy

Member Since 30 Jul 2009
Offline Last Active Jul 22 2012 10:08 PM

Topics I've Started

Preventing secluded rooms

19 July 2012 - 07:07 PM

I'm in the early stages of developing a Roguelike (or Dungeon Crawler, whatever you want to call it), and it's been going alright so far.
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] = hallW

And 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] = hallW

The 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.

Collision Masks don't flip?

04 May 2012 - 05:25 PM

[SOLVED]
If an enemy is facing right, the masks work fine. But when it faces left, the masks still act like it's facing right. Either I don't know how to flip masks, or it's impossible.
Even if it's impossible, it's no big deal. I can just create separate masks for the sprite facing left and right. But is it possible at all to flip masks, or is doubling my masks the way to go?

Having trouble understanding arguments

27 April 2012 - 10:28 PM

FIXED.



Title Screen:
global.timeRecord01 = 9999999

I have a persistent object with this code:
scr_BossArrays()

scr_BossArrays:
global.timeRecord[1] = global.timeRecord01

Boss Create Event:
global.bossNo = 1

When the boss dies:
if global.bossTotalHP <= 0
    {
    script_execute(scr_EndFight,boss01_A,boss01_B,boss01_C,global.timeRecord01)
    }

scr_EndFight:
if global.timeValue < global.timeRecord[global.bossNo] && global.title != 12
    {
    global.timeRecord[global.bossNo] = global.timeValue
    }

Here's the relevant code that I need help with.

if global.bossTotalHP <= 0
    {
    script_execute(scr_EndFight,boss01_A,boss01_B,boss01_C,global.timeRecord01)
    }
boss01_A, B, and C are all constants that work perfectly.
global.timeRecord01 is your best time on the first boss, in tenths of a second.

scr_EndFight:
if global.timeValue < argument3
    {
    argument3 = global.timeValue
    }

This code changes your best time if you beat the boss more quickly. However, it always changes, regardless of your time.
So what can I do to fix this? There's obviously something I don't fully understand.

Creating way too many objects

13 August 2011 - 11:46 PM

I'm working on a new level, and I'm trying to add lava that flows through the room, flooding it. But the problem is that for some reason, it's creating way too many objects (talking like, thousands), when it should be creating just enough to fill the room.

Here's the object (obj_LavaFlood)

Create
alarm[0] = 15

Alarm 0
if x > -16 && y > -16 && x < room_width + 16 && y < room_height + 16
    {
    if !collision_rectangle(x,y + 16,x + 16,y + 31,objSolidTile or objLavaFlood,1,1)
        {
        instance_create(x,y + 16,objLavaFlood)
        }
    if !collision_rectangle(x + 16,y,x + 31,y + 16,objSolidTile or objLavaFlood,1,1)
        {
        instance_create(x + 16,y,objLavaFlood)
        }
    }

So you can see that is checks if the current lava tile is within the boundaries of the room.
If it is, then it checks if there's a solid tile or lava tile below it. If not, it creates a new one.
Then the same thing for the tile in front of it.

I've tried a few different things, collision_rectangle, collision_point, place_free... but it all starts creating way too many objects. This is probably, like most of my problems, something incredibly obvious that I'm overlooking.

Can't manually set bounding box of each subimage?

09 August 2011 - 08:28 PM

Even though I check Seperate Collision Masks (kind of a long shot, I know), every subimage shares the same bounding box when I set it manually.  Is there something I'm missing, or is this a known issue? Is there any kind of workaround for this? I tried to change bbox_top in a step event, but it turns out you can't do that in-game.  So, I'm kinda stumped.