Circle-Rectangle collision detection (intersection)

Here is how I would do it: bool intersects(CircleType circle, RectType rect) { circleDistance.x = abs(circle.x – rect.x); circleDistance.y = abs(circle.y – rect.y); if (circleDistance.x > (rect.width/2 + circle.r)) { return false; } if (circleDistance.y > (rect.height/2 + circle.r)) { return false; } if (circleDistance.x <= (rect.width/2)) { return true; } if (circleDistance.y <= (rect.height/2)) … Read more

How to detect collisions between two rectangular objects or images in pygame

Use pygame.Rect objects and colliderect() to detect the collision between the bounding rectangles of 2 objects or 2 images: rect1 = pygame.Rect(x1, y1, w1, h1) rect2 = pygame.Rect(x2, y2, w2, h2) if rect1.colliderect(rect2): # […] If you have to images (pygame.Surface objects), the bounding rectangle of can be get by get_rect(), where the location of … Read more