Level loading system


So. Level loading, in a way that it you don't need to recompile or even touch the code as you are adding levels- allowing for simply adding user created content and just shipping levels.

The level selection screen in my game as you open it checks for the first levelpack. After finding it it assigns the "levelscreen.png" to a texture. Theres a variable that is the "screen"/or level whichs levelscreen is being shown on the screen. First its 0. If you were to click play now, the game would just in case set the score keeping variables to zero, and depending on if youre opening a single level(yourlevel levels) or a level pack it puts the game to be on career mode- but yeah. So the variable keeping track of the level shown on the menu screen, is used in loading the level to load like this.

PickedLevel = "Levels/LevelPack" + to_string(LevelSelection) + "/Level" + to_string(Career) + "/";

PickedLevel being and std::string used in ifstreaming the contents of the file.  And LevelSelection being the screen selected in the menu. And career being a variable that when going into a levelpack is set to 1. And everytime you finish a level its increased by one. This way we can just use this same line of code while loading every single level. Then, when levels run out, and as its trying to load data from a file that doesnt exist. Theres a line saying that if the file isnt open, then go back to the level selection menu.

Sorry if i explained this badly- 

Get NotThatSad Golf

Leave a comment

Log in with itch.io to leave a comment.