Main Menu

Another Rebouding Ball Example

Started by kevin, January 11, 2006, 03:03:04 PM

Previous topic - Next topic

kevin

Another bouncing ball example :)




Gosub Init_Ball

Do
 Cls 0

  BallX#=BallX#+BallSpeedX#
  BallY#=BallY#+BallSpeedY#
  Circle BallX#,Bally#,5,true

 ; rebound it  
  if BallX#<0 or BallX#>getScreenWidth() then BallSpeedX#=-BallSpeedX#
  if BallY#<0 or BallY#>(getScreenHeight()-10) then BallSpeedY#=-BallSpeedY#

  if Spacekey()
    Gosub Init_Ball
  endif  


 Sync
loop



Init_Ball:


BallX#  =getScreenWidth()/2
BallY#  =getScreenHeight()/2
BallSpeed# =rndrange(1,5)
BallAngle#  =rnd(360)
BallSpeedX#  = Cos(Ballangle#)*BallSpeed#
BallSpeedY#  = Sin(Ballangle#)*BallSpeed#

return