Navigating menus

Blitz3D Forums/Blitz3D Beginners Area/Navigating menus

Hi yahfree,

Thanks for the additional bits. I have found some mistakes and I have a working version here now however, I need some time to show you the changes so you can understand. I will attach the new code here for now, but I will explain some more if I get chance tomorrow.

Global selection
Global ingame
ingame = 1
selection = 1
;If selection=1 Mainmenu()
;If selection=2 playgame()
;If selection=3 options()

While ingame = 1 ; loop until ESC is pressed
  If selection = 1 Then
    Mainmenu() ; main menu sets selection to 2 if the play game button is pressed or sets selection to 3 if the options button is pressed.
  ElseIf selection = 2 Then
    playgame() ; move game code into its own function.  When game ends set selection = 1 again to show the main menu.
  ElseIf selection = 3 Then
    options() ; display the options menu.  When the back button is pressed, set selection to 1 and the main menu will be shown.
  End If
Wend

Function Mainmenu()
	Graphics 800,600,32,2


	mainimage=LoadImage("mainmenu.png")
	continue=LoadImage("Playbutton.png")
	;mouse=LoadImage("mouse.png")
	MaskImage continue,255,0,255



	While selection = 1
		;mouse_x=MouseX()
		;mouse_y=MouseY()
		Cls


		DrawImage mainimage,0,0
		DrawImage continue,100,400
		;DrawImage mouse,mouse_x,mouse_y
		Flip

		If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And MouseHit(1)
			selection=2
		End If
		If KeyHit(60) Then
			selection = 2
		End If
		If KeyHit(59) Then
			selection = 3
		End If

		
		Delay 5
	Wend

End Function

;Options
Function options()
	Graphics 800,600,32,2
	
	Backbutton=LoadImage("Backbuttons.png")
	
	While selection = 3
		Cls
		DrawImage backbutton,0,0
		If KeyHit(1) Then
			selection = 1
		End If
		If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
			selection=1
		End If
		Flip
		Delay 5
	Wend

End Function

Function playgame()

	Graphics 800,600,32,2
	;Mid handles all of the images and creates a image called paddle.
	HidePointer
	
	AutoMidHandle True
	   paddle=CreateImage(70,15)
	   ball=CreateImage(10,10)
	AutoMidHandle False
	
	
	;draws on the empty image container..
	SetBuffer ImageBuffer(paddle)
	   Rect 0,0,70,15,1
	SetBuffer ImageBuffer(ball)
	   Oval 0,0,10,10,1
	SetBuffer BackBuffer()
	
	;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
	life1=CopyImage(ball)
	life2=CopyImage(ball)
	life3=CopyImage(ball)
	
	While selection = 2
		Cls
		If KeyHit(1) Then
			selection = 1
		End If
		
		;Calls functions.
		Text 0,0, "IN game"
		
		;conditional functions
		
		;small delay in the loop for less slow down.
		;flips, ends the loop and termanates the program..
		Delay 5
		Flip
	Wend

End Function


I didn't have your pictures and I had to remove some other stuff, hopefully you will get the main idea, but if not, just wait until I can explain more.

Thanks
Tim