One very, very important thing I'd like to add:

Imagine you've got two circles, a and b. If you want the two circles not to collide, you need to check whether the distance between the two circles is greater than the combined radii:

`a.radius + b.radius < distance`So thats exactly what you do, let's fill in the distance formular:

`dx = b.x - a.x`

dy = b.y - a.y

a.radius + b.radius < sqrt(dx * dx + dy * dy)So what's the problem with this? The problem is that

is a (relatively) very slow operation. To get rid of it, simply take the square of the terms:

`a.radius + b.radius < sqrt(dx * dx + dy * dy)`

<=>

(a.radius + b.radius)² < dx * dx + dy * dyAnd in the end that's much faster. It might be premature optimization, but it takes almost no time to understand and change.

I Hope I'm helpful