Sign in to follow this  
Mrduckels

Loading a level, reload my main.cpp file?

Recommended Posts

Mrduckels    106
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
Toolmaker    967
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
Red Falcon    142
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this