Original Post
I'm working on a 2-d RPG, Final Fantasy style. I'm almost finished my battle component (I've started with windowing and battles, then I'm going to work on inventory, spells, maps, etc.). I'm at a point now where I have to worry about two different states, and I'm not sure what to do. The way I was thinking of handling it, was to embed the code to handle the state whenever that states appears. For example, if you press the up arrow key on a map, then you're in the state of "map", and it will move your character up and scroll the game world down (and other stuff, probably). If you press up while in the menu, it moves the menu item up. Each state will also handle it's own graphic processing. I figure any state can be transferred into, and out of. Each state should have a "start" function that will transfer into that state, and then when the start function is finished executing, you are returned back into the initial state. For example: Main screen --> Load game.start() --> Map.start() --> Battle.start() --> Returns to map --> Inventory.start() --> Returns to map --> (User quits) returns to Load game --> Returns to Main screen --> Exits. Accoring to this book, you should create stacks for each state, and then provide each state with functions like "handleKeyboard()", "preRender", "renderFrame", "postRender", etc, and then push and pop the states onto a stack, and call the appropriate functions on the top element of the stack (the current state) as needed. I feel like that's probably a more elegant approach, but a bit complicated for my first game. Any opinions on this are appreciated :)