def collideCircle(ball): """Check for collision between a ball and a circle""" hit = False closestDist = 0 for c in circles: # Code cannot be replaced with physicsEngine.collideTest because it # is slightly differnt, testing if ball [ball] inside a circle [c] dx = c.x - ball.x dy = c.y - ball.y distance = math.hypot(dx, dy) if distance <= c.size - ball.size: # If BALL inside any CIRCLE hit = False break else: # If we're outside of a circle. if closestDist < c.size - (distance - ball.size): hit = c closestDist = (c.size - (distance - ball.size)) if hit: module_physicsEngine.circleBounce(hit, ball)
def collideCircle(ball): """Check for collision between a ball and a circle""" circleIndex = -1 closestDist = 0 hit = False for c in circles: # Check each ball against every circle circleIndex += 1 dx1 = c.x - ball.x dy1 = c.y - ball.y dist1 = math.hypot(dx1, dy1) if dist1 <= c.size - 1: # If we are inside 'c' hit = False break else: # If we are outside 'c' or touching the border remainingCir = circles[:] # Make a new list of only remaining circles for c2 in remainingCir: # Check each remaining circle dx2 = c2.x - ball.x dy2 = c2.y - ball.y dist2 = math.hypot(dx2, dy2) if dist2 <= c2.size: # If we are inside 'c2' hit = False break if c.size - (dist1 - ball.size) > closestDist: hit = c closestDist = (c.size - (dist1 - ball.size)) if hit: module_physicsEngine.circleBounce(hit, ball)