I really ought to write a menu tutorial.
Here goes:
First you need to work out what options the menu will have.
In this example we'll have Start Game, Exit Game.
I am going to assume you're using the mouse.
And I'm going to assume you're using a bitmap or some other graphic for each option.
Firstly write the code that actually starts and exits the game.
Secondly make an array to store information about these icons.
I like a two dimensional array which stores six integers for each element of the GUI.
Dim GUIarray(n,6) where n is the number of elements (2 in this case).
What I store in the other six integer fields is this:
GUIarray(n,1)=visibilityFlag
GUIarray(n,2)=top y coord
GUIarray(n,3)=left x coord
GUIarray(n,4)=bottom y coord
GUIarray(n,5)=right x coord
GUIarray(n,6)=action code
visibilityFlag is a 0 or 1 telling the program if the icon is visible. If it's not visible you don't bother checking if the user's cliked on it.
The coordinates are 2D coordinates on the screen.
the action code is something you make up yourself based on how many different things you want the menu to do.
Here we'll say an action code of 1 means "Start the game" and a code of 2 means "Exit game".
Next we make a function that takes a 2D x and y screen coordinate and checks all the icons in the GUIarray.
function getGUIaction(xClick,yClick)
actionCode=0
for i=1 to size of GUIarray
if GUIarray(n,1)
if (xClick>GUIarray(n,3) and xClick<GUIarray(n,5))
if (yClick>GUIarray(n,2) and yClick<GUIarray(n,4))
actionCode=GUIarray(n,6)
endif
endif
endif
next i
endfunction actionCode
this returns an actionCode for the GUI element clicked on.
An actionCode of 0 does nothing.
No make a fuction that takes the action code and runs the appropriate function or subroutine in reponse:
function doGUIaction(actionCode)
SELECT actionCode
CASE 1:
gosub _start_game
ENDCASE
CASE 2:
gosub _exit_game
ENDCASE
ENDSELECT
endfunction
Now you can write some stuff to control when the GUIarray gets checked.
IF mouseclick()=1
action=getGUIaction(mousex(),mousey())
ENDIF
IF action THEN doGUIaction()
Don't put the "if action then" bit inside the first IF statement if you think you might also want to check the keyboard for GUI hotkeys being pressed. If you want to use keys to trigger GUI actions then you have to add another element to GUIarray to store the scancode of the key that corresponds to that action. e.g. if you want the "s" key to start the game and the "x" key to exit the game as well as clicking on the icons then Dim GUIarray to be (n,7) and set GUIarray(1,7) to be the scan code for "s" and set GUIarray(2,7) to be the scancode for "e".
Now write a function based on getGUIaction that is given a scancode and returns an action by searching GUIarray(n,7).
Now you can check for keyboard presses by putting another IF statement after the IF mouseclick() one but before the IF action one.
Er... give it a go and look up the proper functions for returning a size and a scan code. When you get it working you can improve it so that it checks for UPPER CASE "E" and "S".
If you want a menu system that uses the arrow keys then that's something else (although you'll still need the array of GUI elements). But it's something else I can tell you how to do, though!