So I'm using enum for game states. When I am in the game playing state I can pause and return to the main menu. But if I click Play game and move to game playing again, everything is as I left it. I'm looking for a way to somehow "restart/refresh/flush" the game playing state. So if I go back to it I will have to start over.
2 Answers
You have some code now (one presumes) that initializes your game state when the program starts. You need to factor that code out (if necessary) so that it can also be called to initialize the game state any time you want. Such as when you are starting a new game, i.e. moving your game state to "game playing".
Indeed, most of the initialization code (i.e. everything except the stuff that doesn't need to be reinitialized on a new game), you'll probably want to run only then. Running it when you start up the program and then again later is redundant and will just slow boot times down.
3 Comments
Initialize()?My gameplay class have lists like "Enemies", "Explosions", "Bullets"... and inside Gampleay class i have Init sub that is executed when is state changed to "gameplay". It clears all and load level.
in pseudo code looks like this:
Class GamePlay Sub Init Enemies.Clear() Explosions.Clear() Bullets.Clear() Paralax.Clear() Stars.Clear() LoadLevel(lvl) End Sub Sub LoadLevel(lvl) Stars.Geneate(200) Paralax.Add(new Paralax(type, position, velocity)) End Sub Sub Update if (mainship.fire) bullets.fire() End Sub Sub Draw End Sub End Class
enumadd it.. also show some code so we can see what your enum looks like