SOLVED How do I create a simple random room generator?

Ham

Member
Currently in a 48 hour game jam, so I'm a bit in a rush to create a quick and simple room generator. I just need a 1920 by 1080 room generated, then random patches of collidable objects are littered over the room. I need there to be much more space then there is walls because the it's a bullet hell and the player and bullets need space to move around in. Thank you in advance.
 
I mean, you can do it really quick and dirty by simply keeping a list of what you have placed as you place it and each time you go to place a new thing, just loop through the list and make sure the distance is some minimum from each list item. Exit the placing loop once you've placed enough objects (which you can either do by just setting a number and tweaking that until the room is full enough or maybe when there's no places free that are the minimum distance from everything else in the placed list). But writing a cellular automata algorithm with some good tweaking of the settings should net you a nicer version of what you are trying to do. Just depends on your competence level and how much time you have left.
 

Fabseven

Member
create a grid, the grid represent your room in your grid 0= empty space (grass) 1=tree, set the whole grid at 1 then use a script doing this :

1- Create a room , size = 3x3 or 4x4 or 5x5 or whatever -> save the room location and size somewhere, one ways is to create an obj_room with prop of your room
2- choose a direction up,down,left,right
3- move for a randomised number of cell in the chosen direction
4- If the current cell isn't in a room (that's why you have to store your room's location and position like in 1) then create a room and store it's location/prop, if the room cannot be create return to step 2

stop when you have a defined number of room or after a defined number of iteration in your main loop or when you cannot create any more room
btw setting a room mean set values 0 around the current location.
 

Fabseven

Member
in the end you "draw" your field/map with tiles

show_debug_message("Field_draw" + string(nbr_cell_www*nbr_cell_hhh))

Code:
for(xxx = 0; xxx <= nbr_cell_www -1 ; xxx++)
{
    for(yyy =0 ; yyy <= nbr_cell_hhh -1 ; yyy++)
    {
//        tile_add(back,,cell_www,cell_hhh,0,0,ddepth)
        if( ds_field[#xxx,yyy] == FIELD_A1) {

            tile_add(back,cell_www*1,0,cell_www,cell_hhh,obj_field_limit1.x+ xxx*cell_www,obj_field_limit1.y+yyy*cell_hhh,ddepth)
            mp_grid_add_cell(mp_grid,xxx,yyy)
           
        }
       
        if( ds_field[#xxx,yyy] == FIELD_0) {
           
        }
    }
}
 
Top