Case structure for states can look like this:
Code:
// In render loop
case MainState of
  msIntro: RenderIntro;
  msMenu: RenderMenu;
  msGame: RenderGame;
end;
...
// In the game loop
case MainState of
  msIntro: LoopIntro;
  msMenu: LoopMenu;
  msGame: LoopGame;
end;
If you need to add another state, you can just make new procedures, and make related code there very cleanly. If you need substates, you can make new similar case inside LoopMenu for example. Depending on implementation, i might use menu classes of nxpascal, similar to IDE components in practise. If i click "Start game" button:
- In component approach the onClick event would be raised and handled, and then call StartGame() in it. I could simply hide or show entire panels of buttons and things.
- Oldschool way a StartGame() procedure would be called directly in some onMouseDown/Up/click event. There needs to be some integer variable telling index of button that was mouse-focused, and another variable telling which menu is open.
Another variables handling fadein, fadeout of states. Usually i only set NewState:=msGame; or something in the StartGame(). After the msGame has faded out, then set MainState:=NewState; . This can happen in the general loop, common for all states.