Hey, i'm trying to make this little paddle mouse controled, and my problem is, the mouse goes off the window to easy, is there any way how i can lock the mouse in the center of the window and still use it to move this paddle around?
heres the code it should work with no media:
as you can see the mouse can easly run off the screen leavin the player useless untill he gets it back on there, how can i lock it into a place?
heres the code it should work with no media:
;Breakout by Yahfree ;2007-04-4 -> ????-??-(?)? AppTitle "Breakout by Yahfree","Are you sure?" HidePointer ;sets the graphics mode, and the setbuffer Graphics 800,600,32,2 SetBuffer BackBuffer() ;Globalized stuff Global paddle, paddlex=380, paddley=560 Global ball,ballx=380, bally=580, ballxdir#=0, ballydir=-1, move=1 ;Global blope=LoadSound("Beep.wav") ;Constant numbers that never change.. Const ESC=1, RIGHTARR=205, LEFTARR=203, SPACE=57, MOUSE1=1 ;Mid handles all of the images and creates a image called paddle. AutoMidHandle True paddle=CreateImage(70,15) ball=CreateImage(10,10) ;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() ;!@!@!@!@!@!@!@!@!@!@!@!@!@!@ ;!@!@!@!@ MAIN LOOP !@!@!@!!@ ;!@!@!@!@!@!!@!@!@!@!@!@!@!@! While Not KeyHit(1) Cls addplayercontrols() DrawImage paddle,paddlex,paddley DrawImage ball,ballx,bally addcollisions() ;small delay in the loop for less slow down. ;flips, ends the loop and termanates the program.. Delay 5 Flip Wend End ;Include "Functions.bb" ;Player controls Function addplayercontrols() ;Balls spot if move=1 If move=1 ballx=MouseX()-35 If move=1 And ballx<35 ballx=35 If move=1 bally=paddley-15 If move=1 ballydir=-1 ballxdir=0 ;Move=2 if the spacebar is pressed If KeyHit(SPACE) Or MouseHit(MOUSE1) move=2 End If ;Paddle controls paddlex=MouseX()-35 If paddlex<35 paddlex=35 ;calls the moveball function if move=2 If move=2 moveball() End If End Function ;Moving the ball Function moveball() bally=bally+ballydir*6 ballx=ballx+ballxdir*6 If bally<0 ballydir=1 ;PlaySound(blope) If bally>600 move=1 ballydir=-1 If ballx<0 ballxdir=1 ;PlaySound(blope) If ballx>800 ballxdir=-1 ;PlaySound(blope) End Function ;All the games collisions.. Function addcollisions() If ImagesCollide(paddle,paddlex,paddley,0,ball,ballx,bally,0) ballxdir=(ballx - paddlex)*.025 ballydir=-1 ;PlaySound(blope) End If End Function
as you can see the mouse can easly run off the screen leavin the player useless untill he gets it back on there, how can i lock it into a place?