Game Development Community

Random Room Generation - Need Suggestions

by Dave Calabrese · in Torque Game Builder · 08/04/2006 (11:02 pm) · 7 replies

I'm trying to create a top-down randomly generated level created from pre-generated rooms. The concept here is to have pretty rooms made up in Photoshop, then brought into T2D and created as 'room' objects, with their doorways defined, and then assemble these rooms into a level in T2D. Problem is, I've been thwarted at everything I have come up with to make this happen.

Here is what I have tried... any suggestions to tweak one of these ideas, or a whole new idea, would be awesome!

1.) Have a 'Master Room' object. This object has a grid of link points. The room objects are then mounted to this grid with their sizes being calculated and assigned as blocks to an array to make sure they don't overlap. Abandoned because it for one is far too complicated and could easily lead to disasterous results, and it is incredibly difficult to define the proper door/room placement (or at least it seems to be).

2.) Start with the first room, then mount the second room to the first just so the doorways touch. Now do a check to see if the room collides with any other room. If yes, place the room at another doorway. Keep doing this until one of the rooms in the alotted stack is fit, or the everything in the stack has been tried. Once the room has been put into position, unlink it so we don't accidentally create a link-loop. Abandoned because I cannot find any way to tell TGB to Link Object A from Link Point 1 to Object B at Link Point 2 - I can only seem to link Object A to Object B using the center of Object A as the pivot point.

3.) Mount Room A to Room B at the center point of Room B, then move Room A to one of the doorways. Abandoned because this is just ridiculously complex.

'2' appears to be the best method of all the above - however the 'can only mount at the center of an object' thwarted that. I know there is an object.setLinkNode(), however it only seems to affect where on Object B that I link Object A to - it doesn't change where the pivot is on Object A.


Ideas? Suggestions? Thoughts? Anything would be helpful!

#1
08/05/2006 (1:38 am)
Why do you want to use mounting at all? Just normally place the rooms where you want them to be. Set them to be immovable if you don't want to be moved.
#2
08/05/2006 (7:06 am)
There is offset X n Y parameters in the mount function.
#3
08/05/2006 (7:53 am)
I'm using the mounting so that I can place Room A's doorway at Room B. I would just place them where I want them to be, but the levels are to be randomly generated, so I can't just place them where I want. I have to be able to place a room attached to another room so their doorways touch.
#4
08/05/2006 (8:07 am)
Kevin: There is an offset, however it only says where to offset the object you are mounting from the center of the object you are mounting it to. I need to offset the pivot point location on the object that I am mounting. Without offsetting the pivot point, I end up with the object I am mounting always being mounted from its dead center, which I do not want.

Is there any way at all that I can just place a link point 1 on Object A, a link point 2 on Object B, then say "Mount Object A from Link Point 1 to Object B at Link Point 2"? I see that if I just use the regular UI to mount the object, it will create a Link Point on Object B, which I can then move around to move Object A's location, but again, it's always from the center of Object A, which isn't what I want.
#5
08/05/2006 (8:16 am)
You can use the t2dSceneObject::getLocalPoint() and t2dSceneObject::getWorldPoint() methods to calculate the positions yourself.
#6
08/05/2006 (8:20 am)
Michael: I'm not too sure how that would work. I would have 2 seperate objects, each with multiple doorways, and I would need to, after randomly selecting a new room, position it so its doorway touches the doorway of the first room. Problem is, each room is a different physical size, and all objects seem to only be able to have their pivot point at their direct center (0,0). Placing the objects by their X/Y coordinates in the world feels like it could very easily lead to undesired results as well as becoming excessevly complex due to needing to store the physical dimensions of everything, the X/Y locaiton of each doorway, etc, and then having the level creation logic feed from this bulk of values to place and check everything. Unless there is something I'm missing to that....?
#7
08/05/2006 (9:50 am)
Dave,

I suppose you have stored your that position of your doorways as link points. So if you want to connect on room A and room B together at their link points 0 you could do something like that:
function linkRooms( %roomA, %roomB, %linkPointIdA, %linkPointIdB )
{
    %doorPosition = %roomA.getLinkPoint( %linkPointIdA );

    %roomBoffset = t2dVectorSub( %roomB.getPosition(), %roomB.getLinkPoint( %linkPointIdB ) );

    %roomB.setPosition( t2dVectorAdd( %doorPosition, %roomBoffset ) );
}

That should place roomB at the appropriate position.
If that doesn't help you could post a bit more info about how you store your rooms and the doorway positions in every room.