Quote: "The bit I struggle with is putting together a large program, that could have multiple menus, options for the player to choose and so on. I haven't found many examples to learn from so, for my current project, I sort of had to work it out for myself. I got something working but I'm not overly happy with it. Maybe it's just part of the learning process. "
this little problem i'm quite proud of overcoming. I actually have a menu/gui function which is called every loop and will display all relevant data as required. It branches nicely with other functions to allow things such as highlighting of text with whichever option is currently selected. Mouse/keyboard selection of items and enabling or disabling input control depending on the menu you are currently on. As I said it's called every single loop so regardless of whether you are ingame, or at the main menu, or at the options screen it will show the relevant data (or none at all)
Here's a snippet
Do
Menu(MenuSelection(0))
sync
Loop
function Menu(MenuType$)
if MenuType$<>"ingame" then hide all sprites
for i=1 to 100
if zone exist(i) then clear zone i
Next i
if KeyCheck(200) or KeyCheck(17) then if MenuSelection(0)<>"gamelobby" then if val(MenuSelection(1))>1 then i=val(MenuSelection(1)) : dec i,1 : MenuSelection(1)=str$(i)
if KeyCheck(208) or KeyCheck(31) then if MenuSelection(0)<>"gamelobby" then if val(MenuSelection(1))<val(MenuSelection(10)) then i=val(MenuSelection(1)) : inc i,1 : MenuSelection(1)=str$(i)
if KeyCheck(2) and val(MenuSelection(10))=>1 then MenuSelection(1)="1"
if KeyCheck(3) and val(MenuSelection(10))=>2 then MenuSelection(1)="2"
if KeyCheck(4) and val(MenuSelection(10))=>3 then MenuSelection(1)="3"
if KeyCheck(5) and val(MenuSelection(10))=>4 then MenuSelection(1)="4"
if KeyCheck(6) and val(MenuSelection(10))=>5 then MenuSelection(1)="5"
if KeyCheck(7) and val(MenuSelection(10))=>6 then MenuSelection(1)="6"
if KeyCheck(8) and val(MenuSelection(10))=>7 then MenuSelection(1)="7"
if KeyCheck(9) and val(MenuSelection(10))=>8 then MenuSelection(1)="8"
if MenuSelection(0)="main"
MenuSelection(10)="4" // maximum entries in this stage of the menu, used to prevent the selection going out of bounds
// Menu Bar
size sprite 1,screen width()/1.5,screen height()/11 : sprite 1,screen width()/2-sprite width(1)/2,20,1 : show sprite 1 // sprite 1 is my background image for any simple text boxes
a2boxtext Verdana(40),Sprite x(1),sprite y(1),SpriteX2(1),SpriteY2(1),"Main Menu",1,1,0,rgb(255,0,50,255)
// Menu Selections
size sprite 2,screen width()/3.5,screen height()/13 : sprite 2,screen width()/12,screen height()/2-200,1 : show sprite 2
size sprite 3,screen width()/3.5,screen height()/13 : sprite 3,screen width()/12,screen height()/2-120,1 : show sprite 3
size sprite 4,screen width()/3.5,screen height()/13 : sprite 4,screen width()/12,screen height()/2-40,1 : show sprite 4
size sprite 5,screen width()/3.5,screen height()/13 : sprite 5,screen width()/12,screen height()/2+40,1 : show sprite 5
A2boxtext Verdana(26),Sprite x(2),sprite y(2),SpriteX2(2),SpriteY2(2),"Single Player",1,1,0,SelectionColor(1)
A2boxtext Verdana(26),Sprite x(3),sprite y(3),SpriteX2(3),SpriteY2(3),"Host Multiplayer",1,1,0,SelectionColor(2)
A2boxtext Verdana(26),Sprite x(4),sprite y(4),SpriteX2(4),SpriteY2(4),"Join Multiplayer",1,1,0,SelectionColor(3)
a2boxtext Verdana(26),Sprite x(5),sprite y(5),SpriteX2(5),SpriteY2(5),"Quit Game",1,1,0,SelectionColor(4)
set zone 1,sprite x(2),sprite y(2),spriteX2(2),spriteY2(2)
set zone 2,sprite x(3),sprite y(3),spriteX2(3),spriteY2(3)
set zone 3,sprite x(4),sprite y(4),spriteX2(4),spriteY2(4)
set zone 4,sprite x(5),sprite y(5),spriteX2(5),spriteY2(5)
if MouseCheck(1) and zone(mousex(),mousey())=0 then MouseLocked(1)=1
if KeyCheck(28) or MouseCheck(1) and zone(mouseX(),mousey())>0
if MouseCheck(1) then MouseLocked(1)=1 : if zone(mouseX(),mouseY())<>0 then MenuSelection(1)=str$(zone(mouseX(),mouseY()))
if MenuSelection(1)="4" then play sound 1 : wait 250 : end
if MenuSelection(1)="1" then play sound 1
if MenuSelection(1)="2" then play sound 1 : menuSelection(0)="host" : MenuSelection(1)="1"
if MenuSelection(1)="3" then play sound 1 : menuSelection(0)="join" : MenuSelection(1)="1"
Endif
Endif
Endfunction
function SpriteX2(Var)
i=sprite x(Var)+Sprite Width(Var)
Endfunction i
function SpriteY2(Var)
i=sprite y(Var)+Sprite Height(Var)
Endfunction i
function SelectionColor(Var)
i1=rgb(255,255,20,20) // Selected Color
i2=rgb(255,183,62,255)// Not Selected Color
if val(MenuSelection(1))=Var then i=i1 else i=i2
Endfunction i
function KeyCheck(i)
i2=0
if i=0
for i3=1 to 255
if keystate(i3)=0 then KeyLocked(i3)=0 : KeyRepeating(i3)=0 : KeyTimer(i3)=hitimer(1000)
Next i3
Endif
if KeyLocked(i)=0 and keystate(i)=1 then KeyLocked(i)=1 : i2=1 : KeyTimer(i)=hitimer(1000)
if keystate(i)=0 then KeyLocked(i)=0 : KeyRepeating(i)=0
if keystate(i) then if i>1 and i<28 or i>29 and i<42 or i>42 and i<54 or i=57 or i>70 and i<84 or i=181 or i=199 or i=200 or i=201 or i=203 or i=205 or i>206 and i<212 // check for valid repeatable keys
if KeyRepeating(i)=0 and hitimer(1000)-KeyTimer(i)=>KeyTimer(0) then KeyRepeating(i)=1 : KeyLocked(i)=0
if KeyRepeating(i)=1 and hitimer(1000)-KeyTimer(i)=>KeyTimer(1) then KeyLocked(i)=0 : KeyTimer(i)=hitimer(1000)
Endif
Endfunction i2
function MouseCheck(i)
i2=0
i3=mouseclick()&&i
if MouseLocked(i)=0 and i3>0 then i2=1
if MouseLocked(i)=1 and i3=0 then MouseLocked(i)=0
endfunction i2
That won't compile directly but you seem to enjoy reading over code so go nuts with it. It's not perfect and I will tweak the function to require less lines of code in each 'section' later on. For now it works fine and I have more important things to focus on
Here is it in a compiled project http://www.2shared.com/file/W6FOR_U6/Shuffle_it.html
mouse click/enter to activate selection (note that holding the mouse button or enter will not keep on 'selecting', it locks/unlocks), WASD/Arrow keys to change selection (changes colour of current selection)
Supports button repeating - and repeat delay - on most keys, but excluding others such as enter/escape. Note when entering your name, or using arrow keys/WASD you can hold buttons and they'll repeat. Though enter will NOT to prevent spamming through the menu's. The 'max players' field normally allows you to use A/D/Left/Right to change the value, however i've locked it at 2 players for this project
Oh and the multiplayer system with game lobby should work fine, just open 2 instances and join urself. Note the ping display works (host may not be visible, slight niggle i'll fix later)
And while i'm yet to apply the required tweaks to make it perfect, the menu system does indeed support multiple resolutions to an extent (game lobby is the exception atm), edit the settings.cfg file