Ok, that seems to work on the some buttons work some don't problem, but i still cant figure out for the life of me why i cant get it when esc is pressed to go back to the mainmenu
i'll give you all my code:
PS. I have the Delay 5 in the main loops because it makes no difference in the program but a HUGE difference in how much CPU it uses
i'll give you all my code:
;Breakout by Yahfree ;2007-04-4 -> ????-??-(?)? AppTitle "Breakout by Yahfree","Are you sure?" ;Globalized stuff Global paddle, paddlex=380, paddley=560 Global ball,ballx=380, bally=580, ballxdir#=0, ballydir=-1, move=1, ballsleft=3, life1, life2, life3 Global blope=LoadSound("Beep.wav") Global pausedpic Global selection Global ingame ;Constant numbers that never change.. Const ESC=1, RIGHTARR=205, LEFTARR=203, SPACE=57, MOUSE1=1, A=30, Z=44, P=25 ingame = 1 selection = 1 While ingame=1 If selection = 1 Then Mainmenu() ElseIf selection = 2 Then playgame() ElseIf selection = 3 Then options() End If Delay 5 Wend ;Include "Functions.bb" ;Player controls Function addplayercontrols() ;Paddle movemovement and controls paddlex=paddlex+MouseXSpeed() MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 If paddlex<35 paddlex=35 If paddlex>765 paddlex=765 ;Ball control. If move=1 ballx=paddlex If move=1 And ballx<35 ballx=35 If move=1 bally=paddley-15 If move=1 ballydir=-1 ballxdir=0 If MouseHit(MOUSE1) move=2 End If ;calls the moveball function if move=2 If move=2 moveball() End If End Function ;Moving the ball Function moveball() ;All physics behind moving the ball and bouncing it. bally=bally+ballydir*10 ballx=ballx+ballxdir*10 If bally<0 ballydir=1 PlaySound(blope) If bally>600 move=1 ballydir=-1 ballsleft=ballsleft-1 If ballx<0 ballxdir=1 PlaySound(blope) If ballx>800 ballxdir=-1 PlaySound(blope) End Function ;All the games collisions.. Function addcollisions() ;collisions If ImagesCollide(paddle,paddlex,paddley,0,ball,ballx,bally,0) ballxdir=(ballx - paddlex)*.025 ballydir=-1 PlaySound(blope) End If End Function ;Draws the images Function drawmyimages() ;Draws the images... DrawImage paddle,paddlex,paddley DrawImage ball,ballx,bally If ballsleft>2 DrawImage life3,680,580 If ballsleft>1 DrawImage life2,700,580 If ballsleft>0 DrawImage life1,720,580 If ballsleft=0 ballsleft=3 DrawImage Backbutton,0,0 End Function ;Text maths ect... Function addtext() Text 0,0,selection End Function ;Pause function, called when P is pressed Function Pause(picture) FlushKeys While Not KeyHit(P) DrawImage picture,0,0 Flip Cls If KeyHit(1) Then End End If Delay 5 Wend End Function ;!@#!@#$@#$!$#!$@#$!@$#@ ;!#@!@# MAINMENU !@#!@#@ ;!@#!@#!@#!@#@!#!@#!@#@# Function Mainmenu() Graphics 800,600,32,2 ;Load/creates images mainimage=LoadImage("mainmenu.png") continue=LoadImage("Playbutton.png") options=LoadImage("options.png") MaskImage continue,255,0,255 MaskImage options,255,0,255 ;Mainmenu loop While selection=1 Cls ; draw the images DrawImage mainimage,0,0 DrawImage continue,100,400 DrawImage options,100,450 mouseclick1=MouseHit(1) ;Collisions basicly making the buttons work If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And mouseclick1 selection=2 End If If ImageRectCollide(options,100,450,0,MouseX(),MouseY(),5,5) And mouseclick1 selection=3 End If If KeyHit(2) selection=3 End If ;if esc is pressed ONLY AT THE MAIN MENU quit. If KeyHit(1) ingame = 0 selection = -1 End If ;delay and bye bye loop Delay 5 Wend End Function ;!#!@#!@#!@#!@#!@#!@#! ;!@#!@ OPTIONS !@#!@$$ ;#@!#!@$#@$@#$@#$@#$@# Function options() Graphics 800,600,32,2 backbutton=LoadImage("Backbuttons.png") MaskImage backbutton,255,0,255 ;options loop While selection=3 Cls DrawImage backbutton,0,0 ;Makes the buttons work If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1) selection=1 End If ;delays and bye bye loop Delay 5 Wend End Function ;!#$@#$@#%@!#$@#$!@#$!@#$ ;@#$@#$# PLAYGAME !@#!@## ;!@#!@$@#$@#$@#$@#$@#$@#$ Function playgame() ;Graphics mode set for playgame() Graphics 800,600,32,2 HidePointer ;Loads/Creates all the images AutoMidHandle True paddle=CreateImage(70,15) ball=CreateImage(10,10) AutoMidHandle False pausedpic=LoadImage("Paused.png") ;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) ;playgame() loop While selection=2 Cls ;Calls functions. addplayercontrols() drawmyimages() addcollisions() addtext() ;if keyhit 1 (ESC) then SUPPOST TO GO BACK TO MAIN MENU If KeyHit(1) selection=1 End If ;conditional functions If KeyHit(P) Pause(pausedpic) End If ;small delay in the loop for less slow down. ;flips, ends the loop and termanates the program.. Delay 5 Flip Wend End End Function
PS. I have the Delay 5 in the main loops because it makes no difference in the program but a HUGE difference in how much CPU it uses