I've been working on making a simple clone of the Perfect Dark Menu system, and the way I've wrote my menu system I think is quite clunky and would be better done as a seperate function with cases but I am struggling to wrap my head around it.
I know the IF statements are both ugly and impractical, would anyone be able to walk me through writing a better system please, I've included the code below..
Code: Select all
@DISPLAY {width = 320, height = 240, ScaleMode = #SCALEMODE_AUTO, ScaleWidth = #NATIVE, ScaleHeight = #NATIVE}
NUMBER = 3
menuvar = 2
OpenMusic(1,"pdtraining.mod")
LoadBrush(1,"pd.jpeg",{scalewidth = 320, scaleheight = 240})
LoadSample(1,"menu.iff")
BlurBrush(1,NUMBER)
BrushToBGPic(1,1)
PlayMusic(1)
Function p_render()
SetFont(#SANS, 12)
CreateBrush(10,160,20,$2F52C9,{AlphaTransparency = True})
CreateTextObject(1,"Small but Perfect Menu",{ALIGN = #LEFT,COLOUR = #WHITE})
CreateBrush(11,160,140,$0E204A,{AlphaTransparency = True})
SetFont(#MONOSPACE, 15)
If menuvar = 2
CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
If menuvar = 3
CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
If menuvar = 4
CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
If menuvar = 5
CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
If menuvar = 6
CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
BeginRefresh()
Cls()
DisplayBGPic(1)
DisplayBrush(10,80,20,{transparency = "25%"})
DisplayTextObject(1,100,22)
DisplayBrush(11,80,40,{transparency = "50%"})
Global k = 0
For i = 2 To 6 Step 1
DisplayTextObject(i,120,48+k)
If i = 5
k = k + 25
Else
k = k + 25
EndIf
Next
EndRefresh()
EndFunction
Function p_logic()
If kbUP = 1
If menuvar = 2
menuvar = 2
Else
PlaySample(1)
menuvar = menuvar - 1
EndIf
EndIf
If kbDOWN = 1
If menuvar = 6
menuvar = 6
Else
PlaySample(1)
menuvar = menuvar + 1
EndIf
EndIf
EndFunction
Function p_mainloop()
p_render()
p_logic()
EndFunction
Function p_HandlerFunc(msg)
;SWITCH FOR HANDLER FUNC
Switch(msg.action)
Case "OnRawKeyDown":
Switch UpperStr(msg.key)
;Movement Flags Down
Case "UP":
kbUP = 1
Case "DOWN":
kbDOWN = 1
Case "ESC":
End()
EndSwitch
;Movement Flags Up
Case "OnRawKeyUp":
Switch UpperStr(msg.key)
Case "UP":
kbUP = 0
Case "DOWN":
kbDOWN = 0
Case "ESC":
End()
EndSwitch
;Switch for Handler Func
EndSwitch
EndFunction
SetInterval(1,p_mainloop,40)
InstallEventHandler({OnRawKeyDown = p_HandlerFunc, OnRawKeyUp = p_HandlerFunc})
Repeat
WaitEvent
Forever