The dist() function is useful if you opt for Circle Collisions –
def setup():
size(500, 500)
def draw():
background(0)
dog_x, dog_y, dog_r = width/2, height/2, 100
ball_x, ball_y, ball_r = mouseX, mouseY, 50
# draw 'dog'
fill('#0000FF') # dog is always blue
circle(dog_x, dog_y, dog_r*2)
# draw ball
if dist(dog_x, dog_y, ball_x, ball_y) < dog_r + ball_r:
fill('#00FF00') # ball is green touching dog ...
else:
fill('#FF0000') # else ball is red
circle(mouseX, mouseY, ball_r*2)
Of course, this checks for a single dog and ball collision. For multiple dogs (and a single ball), you’ll have to loop through the entire dogs list to detect if any have collided with the ball, then remove those dogs that have (i.e. remove an item from a Python list).