Source Code: Text Menu
rating: 0+x

Explanation

Text Menu is an example of a simple text menu. It is suitable to use for a title screen menu.

Instructions

  • Use the up and down arrow keys to move the menu selector.
  • Press the Enter Key to make a choose a menu item.

Source Code

SetFPS 60

Global menuSelect = 1
Global menuChosen$ = ""

Dim menu$(3)
menu$(1) = "Start Game"
menu$(2) = "High Scores"
menu$(3) = "Credits"

PSub DisplayMenu()
    For i = 1 to 3
        Text 20, 20 * i, menu$(i)
    Next
    Text 10, 20 * menuSelect, "*"    
EndPSub

PSub UpdateMenu()
    If UpKey()
        menuSelect = menuSelect - 1
        If menuSelect < 1
            menuSelect = 1
        EndIf
        FlushKeys
    EndIf
    If DownKey()
        menuSelect = menuSelect + 1
        If menuSelect > 3
            menuSelect = 3
        EndIf
        FlushKeys
    EndIf
    If EnterKey()
            menuChosen$ = menu$(menuSelect)
    EndIf
EndPSub

Do
    Cls 0
            Print "You have chosen : " + menuChosen$
        DisplayMenu()
        UpdateMenu()
    Sync
Loop

Related Pages

How To

Categories: Interfaces : Source Code : Text