• Advertisement
Sign in to follow this  

Loading a level, reload my main.cpp file?

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am making a game for my school project and Im having some troubles with loading a level. Right now all variables for the first level are declared and initialized inside my code, but I want to get it extern - in a text file to be exact -. I already asked in the 'General Programming' forum how I should do this, but there is 1 more thing that is 'Game Programming' like: Many examples I have seen have a menu inside their main-game file (main.cpp for example), I think this is fairly logic but I want to reload my main.cpp file everytime I enter a new level so it would not be smart to throw in my outer layer code (the main menu) inside this reloadable .cpp file. Please try to picture my situation, should I continue in this direction? Or should I not graduate cause of this? :P

Share this post


Link to post
Share on other sites
Advertisement
This is why you need to use a gamestate variable(Or a class) and move your level code into it's own class aswell.

Make a class Level, and give the level to your PlayGame(&Level); function. This way, if your gamestate is set to "load new level", you load a new level, change state to playgame, and hand in the level object.

Toolmaker

Share this post


Link to post
Share on other sites
yup. NEVER put a level code into your main loop. otherwise you will be loading and reloading the main.cpp all the time. just make the software check if the level is done, and then call the next level

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement