Physics How To

Blitz3D Forums/Blitz3D Userlibs/Physics How To

hey, just made it so the ball bounces off the walls

Graphics 1280,1024,0,1
SetBuffer BackBuffer()

xp#=100
yp#=100
xg#=0
yg#=0


While Not KeyHit(1)

   mx=MouseX()
   my=MouseY()

   	
; Directional vector to create speed

   xg=xg+(mx-xp)/100.0
   yg=yg+(my-yp)/100.0

   ; A simple replacement air resistance
   xg = xg *.98
   yg = yg *.98

   ; Speed at the position to apply
   xp=xp+xg
   yp=yp+yg

	If xp < 0 Or (xp + 4 > GraphicsWidth())
		
		xg = -xg
		
	EndIf
	
	
	If yp < 0 Or (yp + 4 > GraphicsHeight())
	
		yg = -yg
		
	EndIf

   Color 255,0,0:Line mx,my,xp,yp
   Color 255,255,0:Oval xp-4,yp-4,9,9,1

   Color 255,255,255:Rect mx-4,my-4,9,9,0

   Flip
   Cls
Wend
End