You could use a simple state engine to figure out what part of the game you are in. Create a variable which will store what stage the game is in. In the main loop you can then use this variable to decide what to do.
eg.
Global gameState = 0
while gameState != 2
select gameState
case 0:
; We are in the title screen
TitleScreen()
case 1:
; we are in the game
MainGame()
wend
The TitleScreen() function can then change the GameState to 2 if the Esc key is pressed.
The mainGame function can change the state back to 0 when the game ends.
You can further improve readablitiy by creating constants for the game states.
Const GAME_TITLE = 0
Const GAME_PLAY = 1
Const GAME_END = 2
Now the code will be
Global gameState = GAME_TITLE
while gameState != GAME_END
select gameState
case GAME_TITLE:
; We are in the title screen
TitleScreen()
case GAME_PLAY:
; we are in the game
MainGame()
wend
This is basically how I tend to write my code. If later on you decide you want another screen to perhaps allow the player to change the controls you just insert a new state.
Const GAME_TITLE = 0
Const GAME_SETCONTROLS = 1
Const GAME_PLAY = 2
Const GAME_END = 3
Global gameState = GAME_TITLE
while gameState != GAME_END
select gameState
case GAME_TITLE:
; We are in the title screen
TitleScreen()
case GAME_SETCONTROLS:
; we are in the game
SetControls()
case GAME_PLAY:
; we are in the game
MainGame()
wend
Now your TitleScreen can check if the users hits the C key or clicks on a button on the screen then it can set the gameState to GAME_SETCONTROLS.
The SetControls function can set the state back to GAME_TITLE when it is finished.
Hope that makes sense.
eg.
Global gameState = 0
while gameState != 2
select gameState
case 0:
; We are in the title screen
TitleScreen()
case 1:
; we are in the game
MainGame()
wend
The TitleScreen() function can then change the GameState to 2 if the Esc key is pressed.
The mainGame function can change the state back to 0 when the game ends.
You can further improve readablitiy by creating constants for the game states.
Const GAME_TITLE = 0
Const GAME_PLAY = 1
Const GAME_END = 2
Now the code will be
Global gameState = GAME_TITLE
while gameState != GAME_END
select gameState
case GAME_TITLE:
; We are in the title screen
TitleScreen()
case GAME_PLAY:
; we are in the game
MainGame()
wend
This is basically how I tend to write my code. If later on you decide you want another screen to perhaps allow the player to change the controls you just insert a new state.
Const GAME_TITLE = 0
Const GAME_SETCONTROLS = 1
Const GAME_PLAY = 2
Const GAME_END = 3
Global gameState = GAME_TITLE
while gameState != GAME_END
select gameState
case GAME_TITLE:
; We are in the title screen
TitleScreen()
case GAME_SETCONTROLS:
; we are in the game
SetControls()
case GAME_PLAY:
; we are in the game
MainGame()
wend
Now your TitleScreen can check if the users hits the C key or clicks on a button on the screen then it can set the gameState to GAME_SETCONTROLS.
The SetControls function can set the state back to GAME_TITLE when it is finished.
Hope that makes sense.