Advertisement
velorek1

menu.bas

Jan 16th, 2022
1,998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim as integer scr
  2.  
  3. 'Globals
  4. Dim shared As integer w, h
  5. Dim shared as String Options(5)
  6. Dim shared as integer currentIndex
  7.  
  8. 'Subs Prototypes
  9. Declare Sub drawScreen()
  10. Declare Sub credits()
  11. Declare Sub startMenu(x as integer, y as integer, fc0 as integer, bc0 as integer, fc1 as integer, bc1 as integer)
  12. Declare Sub printItem(index as integer, x as integer, y as integer, fc as integer, bc as integer)
  13.  
  14. 'Obtain screen details
  15. scr = Width
  16. h = HiWord(scr)
  17. w = LoWord(scr)
  18.  
  19. 'Initial values
  20. currentIndex = 0
  21. options (0) = "Option 1"
  22. options (1) = "Option 2"
  23. options (2) = "Option 3"
  24. options (3) = "Option 4"
  25. options (4) = "Option 5"
  26.  
  27.  
  28. 'Main
  29. drawScreen()
  30. startMenu(10,5,7,0,15,1)
  31. credits()
  32.  
  33. 'SUB declations
  34.  
  35. Private Sub drawScreen()
  36. Color 0,0
  37. CLS
  38. End sub
  39.  
  40. Private Sub printItem(index as integer, x as integer, y as integer, fc as integer, bc as integer)
  41. Locate y,x
  42. Color fc,bc
  43. Print Options(index)
  44. End Sub
  45.  
  46. Private Sub startMenu(x as integer, y as integer, fc0 as integer, bc0 as integer, fc1 as integer, bc1 as integer)
  47. Dim as integer i,j
  48. j=0
  49. 'Print list of options
  50. for i=0 to UBound(options)
  51.     printItem (i, x,y+j,fc0,bc0)
  52.     j=j+1
  53. next
  54.     printItem (currentIndex, x,y+currentIndex,fc1,bc1)
  55.  
  56. do
  57.     While Inkey <> "": Wend
  58.    
  59.     if MultiKey(1) then
  60.       'Escape pressed.
  61.        exit Sub
  62.  
  63.     end if
  64.     if MultiKey(&h50)  then
  65.       'Down arrow key pressed.
  66.        printItem (currentIndex, x,y+currentIndex,fc0,bc0)
  67.        if currentIndex < UBound(Options)-1 then currentIndex = currentIndex + 1
  68.        printItem (currentIndex, x,y+currentIndex,fc1,bc1)
  69.        sleep
  70.        getkey()
  71.     end if
  72.  
  73.     if MultiKey(&h48) then
  74.       'Up arrow key pressed.
  75.        printItem (currentIndex, x,y+currentIndex,fc0,bc0)
  76.        if currentIndex > 0 then currentIndex = currentIndex - 1
  77.        printItem (currentIndex, x,y+currentIndex,fc1,bc1)
  78.        sleep
  79.        getkey()
  80.     end if
  81.  
  82.     if MultiKey(&h1C) then
  83.       'Enter pressed.
  84.        locate 12,10
  85.        color 15,5
  86.        print "You have selected: " + options(currentIndex)  
  87.        sleep
  88.        getkey()
  89.     end if
  90.  
  91.  
  92.      While Inkey <> "": Wend
  93.  
  94. loop
  95. end sub
  96.  
  97. Private Sub Credits()
  98. 'Credits
  99. Color 7,0
  100. CLS
  101. print "Selection Menu test. Coded by Velorek 2022."
  102. End sub
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement