Simple Start Menu

Blitz3D Forums/Blitz3D Beginners Area/Simple Start Menu

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I don't have Blitz in front of me (I'm at work), so I'm writing this blind, but it should give you an idea where to go. Learning to program this kind of stuff is considerably easier in the long-run than relying on 3rd-party apps to code relatively simple mouse-click detection - something you're going to need to know how to do. :)

The basics of this code is the RectsOverlap x,y,width,height,mousex(),mousey(),1,1 command which you'll be using any time you want to detect if the mouse click occured while the cursor was over something on the screen. Get to grips with this command and you'll be fine. :)

Graphics3D 800,600,0,2
SetBuffer BackBuffer()
font=LoadFont("Arial",15)
SetFont font

While result=0
    result=MainMenu()
    ;put these options inside the menu loop, as these
    ;return 0 - continuing the mainmenu loop.
    If result=2 Then result=Options()
    If result=3 Then result=Credits()
    Wend
If result=1 Then StartGame()
;if the result isn't 1, then it must be 4 - hence QUIT
End

Function MainMenu()
    Cls
    Text 400,50,"My Menu",1,1
    Rect 300,100,200,50,0
    Text 400,125,"Start Game",1,1
    Rect 300,200,200,50,0
    Text 400,225,"Options",1,1
    Rect 300,300,200,50,0
    Text 400,325,"Credits",1,1
    Rect 300,400,200,50,0
    Text 400,425,"Quit",1,1
    Flip
    result=0
    While result=0
        mx=MouseX():my=MouseY()
        If MouseHit(1) Then
            If RectsOverlap(300,100,200,50,mx,my,1,1) Then result = 1
            If RectsOverlap(300,200,200,50,mx,my,1,1) Then result = 2
            If RectsOverlap(300,300,200,50,mx,my,1,1) Then result = 3
            If RectsOverlap(300,400,200,40,mx,my,1,1) Then result = 4
            End If
        Wend
    Return result
    End Function

Function Options()
    Cls
    Text 400,300,"Options Screen! Any key to return to main menu",1,1
    Flip
    WaitKey()
    Return 0
    End Function

Function Credits()
    Cls
    Text 400,300,"Credits!!",1,1
    Text 400,330,"Made by BlackD",1,1
    Text 400,400,"Any key to return",1,1
    Flip
    WaitKey()
    Return 0
    End Function

Function StartGame()
    Cls
    Text 400,300,"AND you're away...",1,1
    Text 400,400,"ESC to exit",1,1
    Flip
    While Not KeyHit(1):Wend
    End
    End Function


I'll debug it when I get home if it doesn't work.. it's annoying not being able to hit F5 to test it.. hehe :)

EDIT: oops.. made a mistake with the text.. fixed! :D

+BlackD