' Collision Study Mouse and Ball.bas for QB64 fork (B+=MGA) 2017-08-23
'updated from: Collision study mouse and ball.bas for QB64 fork (B+=MGA) trans 2017-08-20
'translated from "collision mouse study.bas" SmallBASIC version 2017-01-10
'which was modify the yab version from six posts to one mouse
_Title "Collision Study: Mouse versus Ball - bplus"
Const RADIUS
= 30 ' radius for both ball and angle ba
= _Pi(1 / 6) 'ball angle in radiansbx = xmax / 2 'ball x
by = ymax / 2 'ball y
'paddle px, py location
pbDistance
= Sqr((px
- bx
) ^ 2 + (py
- by
) ^ 2) 'LOCATE 1, 1: PRINT px, py, pbDistance 'debug
'show paddle
CircleFill px, py, i
'update ball hit paddle
If Sqr((px
- bx
) ^ 2 + (py
- by
) ^ 2) < RADIUS
* 2 Then ba
= _Atan2(by
- py
, bx
- px
)
'handle ball hit border
If bx
< 0 + RADIUS
Then ba
= _Pi(1) - ba: bx
= RADIUS
If bx
> xmax
- RADIUS
Then ba
= _Pi(1) - ba: bx
= xmax
- RADIUS
If by
< 0 + RADIUS
Then ba
= -ba: by
= RADIUS
If by
> ymax
- RADIUS
Then ba
= -ba: by
= ymax
- RADIUS
'ball angle adjustments to keep between 0 and 2*pi
'OK the ball is here
bx
= bx
+ Cos(ba
) * SPEED
by
= by
+ Sin(ba
) * SPEED
'show ball
Color _RGB(255 - i
* 6, 255 - i
* 6, 255 - i
* 6) CircleFill bx, by, i
'update screen and keep loops under 61 per second
'Steve McNeil's copied from his forum
RadiusError = -subRADIUS
X = subRADIUS
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
Line (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
Line (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
Line (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
Line (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
Line (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF