Each level shouldn't need it's own state. The states should be more like MainMenu & PlayingGame, and maybe LevelLoad too. Anything that functions as its own separate screen is a state. Anything that you overlay onto a state (Pause, Player Menu, HUD, etc) can be implemented easier as a push/pop stack. That way you can draw the whole stack if desired - and your Pause menu can still show the game in the background. When you're done with your Pause menu, you pop it off the stack and gameplay naturally resumes and you don't need to track where you came from, etc. The point of using states is that everything naturally flows from one state to the next - as long as you've defined your states well. The same goes for menus, their submenus, etc. I'm still learning this myself, but that's the advice I keep seeing.
As for the levels, I assume you want more than 2 levels total. Your current approach is fine for just 2 levels, but it'll get really cumbersome when you want to move beyond that. I'd suggest something like this:
Code: Select all
-- In MainMenu, when player selects New Game
gameLevel = 1
state = LevelLoad
-- In LevelLoad state
gameLoad(gameLevel)
state = PlayingGame
-- In PlayingGame, when the goal is reached
gameLevel = gameLevel + 1
gameLoad(gameLevel)