• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Infinite roguelike levels in the same room

Artie_Kyle

Member
What up, peeps!

I'm creating code in my head for a rogue like level design system, and I think I'm coming up with some fairly decent ideas that should work once I input them. The one caveat here is that I'm trying to create all this while in one room only (which is how most people would code this if I'm not mistaken). Question is, how do you reset the room every time you're done with a level without resetting the progress?

Does room_restart() reset the statistics of the objects? Do I have to destroy all the objects and create them again? What is the method most people would use to restart the room and present it as another 'level'?

Cheers everyone, looking forward to your wisdom!
 

samspade

Member
I am also curious. I do mostly what you expect - which is I create all of my levels in the same room. But there's really no reason you would have to do this. If my levels were more different, I might do them in different rooms just to have certain presets more specified.

However, to answer your main question this is my code copy and pasted for starting a new level. There are scripts within scripts that I won't post, but it should give the idea:

Code:
#region //delete current level
//destroy all non-persistent objects
with (all) {
    if (persistent == false) {
        instance_destroy();
    }
}
show_debug_message("---------building new level------------");
#endregion


#region //stop effects
scr_stop_effects()
#endregion


#region //rebuild new level
scr_build_level();
#endregion


#region //set up camera for new level
with (obj_camera_controller) {
    event_user(0);
}
#endregion


#region //set gameplay state
scr_set_gameplay_level_state(gameplay_state.level_running);
#endregion
scr_stop_effects simply makes sure that sounds, particles and so on are stopped. scr_build_level contains a bunch of code and more scripts that build out the level, and then I just update the camera and the game state.

This all happens from my gameplay controller object which is persistent and holds gameplay level 'global' variables and is created at the start of 'gameplay' - e.g. when the player would click new game, start, continue, etc. - and destroyed when the player ends the gameplay - e.g. goes back to the main menu. So for example it does things like initialize the player health to its starting value and then track health upgrades and so on so that when the player is created at the start of each new level it can pull its health from this object.
 
D

Danei

Guest
I do something like this in a single room, and I don't use room_restart(); I use data structures to store all the information about what is in each "room", and destroy all the objects (other than my player character and a couple of controllers) and load up the new objects.

Also, in my experience, no matter how thoroughly I design things in my head, I always find that once I start implementing it, I a) have to do some rethinking about how to do some things, and b) being inspired by new ideas for the project I wouldn't otherwise have had, so I would suggest building testable code ASAP.
 

TheouAegis

Member
If you are worried about certain things being reset when you use room restart, then make them global such as global variables or use data structures.
 

Artie_Kyle

Member
If you are worried about certain things being reset when you use room restart, then make them global such as global variables or use data structures.
That's what I'm trying to do now, and it's working with things like the bullets and abilities bar, but will need to figure out a way to create the walls in logical locations.

I'm thinking of a level creator object that basically thinks, if walls<50, keep creating them, else destroy the object. I'd add a few conditions to make sure the walls aren't created in weird places, while being created on a grid so that they aren't created within one another.

I'm fairly confident I'll bump into a sh*t ton of issues, but you live and learn, so I expect I'll be getting a headache or two on this one.
 

TheouAegis

Member
There are a lot of articles out there on the internet about creating roguelike random rooms. Typically you place rooms around the map and connect them with halls. Or you place preset rooms around on a grid randomly.
 
Coding proc gen in your head is a recipe for disaster, imo. I've done a lot of work on proc gen stuff and it almost -never- plays out the way you expect. As @Danei suggested, I'd actually start work on building something because you'll probably find that you have to throw out everything you did in your head.
 

Artie_Kyle

Member
Coding proc gen in your head is a recipe for disaster, imo. I've done a lot of work on proc gen stuff and it almost -never- plays out the way you expect. As @Danei suggested, I'd actually start work on building something because you'll probably find that you have to throw out everything you did in your head.
Working on it now, and the only thing I'm contemplating at the moment is this: Should I create a few walls that are 64x32 and 32x64 to save some space, or have them all 32x32? This works, but when you have 200-300 walls in the same room and you haven't even added the enemies in the game yet, that's going to slow things down I would imagine.
 
D

DekuNut

Guest
you can you can scale your obj_wall can't you? Just figure out how to get the game to know how much to scale it. I'm assuming obj_wall is invisible and only exists for collisions.
 
Top