Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading a level, reload my main.cpp file?

Started by Mrduckels Nov 25, 2004 at 3:54 AM 2 replies 700+ views
Original Post
Mrduckels
Mrduckels
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
;D 'Game-Power? Let players form their wishes within the code-range' ->> RPG me please. ;)
Toolmaker
Toolmaker
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
 
Red Falcon
Red Falcon
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
Mrduckels
Mrduckels
Thank you both.
;D 'Game-Power? Let players form their wishes within the code-range' ->> RPG me please. ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.