Level management

Started by
4 comments, last by LeeWalker 12 years ago
Over the last few days, I've picked up my games programming project once again.

Where I was up to was to implement trigger zones and manage level changes.

I've now done the triggers, however the problem area now lies within the way I thought about implementing the level changes. This is as follows:
- Level class
- Overall level object which holds the current level instance
- The level class has a "nextmap" filename

Once the "End" trigger is reached, the current level will unload it's self and create a new instance which gets assigned to the overall level object. This then will load the new level - one problem here is that there will be no loading screen as a result of this, however I feel like I know a method of implementing that.

I feel like there is a problem in doing this however I'm not entirely sure what it is.
Follow me on twitter! @lwalkeruk
Watch me on youtube! LeeWalkerGM
Advertisement
Have a search for state machines, as these will fix your issue here, there is more to a game then just a level.
A simple game based state machine code look like this:
Menu State (contains press start screens and main menu and the likes)
Loading State (takes care of level loading and unloading)
Level State( this is the container for the current level being played)

Game loop would look like
Menu state -> loading state -> level state -> loading state. After this you can either go back to menu state or level state.

This allows you to move the loading of the level away from the actual level and game code. In each of these states you can run another state machine again, eg Menu state could have a main menu and options menu between which you can transition.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

After looking into the State Machine, this will be quite a time-consuming thing to implement.

I think it's probably the best thing to try for though, it seems to make sense!

Thank you very much NightCreature83
Follow me on twitter! @lwalkeruk
Watch me on youtube! LeeWalkerGM
It takes hardly any time at all and is the proper way to go.
One level should not know about any other level. If a level has a file name for the next level, you are doing it wrong. Save that kind of information for a higher-level structure.

What if you want to get to level 3 via a save feature? Do you have to load levels 1 and 2 to get the file name for level 3 or do you have to duplicate the level table? It doesn’t make sense that levels know about other levels.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Well after about an hour's worth of solid work, I've managed to get the loading screen and gameplay working 100% I've just got to work on the Main menu now so you're quite right, it barely takes any time to get the state machine in place.
Follow me on twitter! @lwalkeruk
Watch me on youtube! LeeWalkerGM
and with regards to your comment about a map not knowing what map is next, I've changed it so that each "end" trigger has an attribute which contains the next map's information. Obviously leading to me creating a hubworld and utilizing this method of going about things.

This approach is also good because I can then have the player load into the hubworld every time, then enter the level where they left off.
Follow me on twitter! @lwalkeruk
Watch me on youtube! LeeWalkerGM

This topic is closed to new replies.

Advertisement