Mouse going off window

Blitz3D Forums/Blitz3D Beginners Area/Mouse going off window

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.

It's delaying because you are updating the ball's position before updating the paddle's position, making it lag a frame behind.

;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()

;Paddle controls
paddlex=paddlex+MouseXSpeed()
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If paddlex<35 paddlex=35
If paddlex>760 Then paddlex=760;NEW!!!!!!!!!!!!!!!!!!!!!!!

;MOVED-------------------------\/
;Balls spot if move=1             
If move=1 ballx=paddlex
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



;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