_TITLE "Ball Collision - use left mouse button to move red ball" ' by ED12345 copied from [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] 2018-04-02
CONST leftMouseButton
= 1
ball.x = 200: ball.y = 200
target.x = 600: target.y = 400
ball.radius = 50
target.radius = 50
CIRCLE (ball.x
, ball.y
), ball.radius
, RED
CIRCLE (target.x
, target.y
), target.radius
, BLUE
distance!
= _HYPOT((ball.x
- target.x
), (ball.y
- target.y
))
IF distance!
<= ball.radius
+ target.radius
THEN
overlap! = (distance - (ball.radius + target.radius)) * 0.5
ball.x = ball.x - overlap! * (ball.x - target.x) / distance!
ball.y = ball.y - overlap! * (ball.y - target.y) / distance!
target.x = target.x - overlap! * (target.x - ball.x) / distance!
target.y = target.y - overlap! * (target.y - ball.y) / distance!