circle-circle collision

Collision between circles is easy. Imagine there are two circles: C1 with center (x1,y1) and radius r1; C2 with center (x2,y2) and radius r2. Imagine there is a line running between those two center points. The distance from the center points to the edge of either circle is, by definition, equal to their respective radii. … Read more

Cone to box collision

I was curious and planned to do stuff needed for this in GLSL math style anyway. So here a different approach. Let consider this definition of your cone: create a set of basic geometry primitives You need to support points,lines,triangles,convex triangulated mesh,spherical sector (cone). implement inside test between point and triangle,mesh,cone for triangle the results … Read more

Pygame mask collision

Your application works fine. But note, pygame.sprite.collide_mask() use the .rect and .mask attribute of the sprite object for the collision detection. You have to update self.rect after rotating the image: class Box(pygame.sprite.Sprite): # […] def rotate(self): self.angle += 3 new_img = pygame.transform.rotate(self.image, self.angle) new_rect = new_img.get_rect(center=self.rect.center) # update .rect attribute self.rect = new_rect # <—— … Read more

Improving performance of click detection on a staggered column isometric grid

This answer is based on: 2D grid image values to 2D array So here it goes: conversion between grid and screen As I mentioned in comment you should make functions that convert between screen and cell grid positions. something like (in C++): //————————————————————————— // tile sizes const int cxs=100; const int cys= 50; const int … Read more

Pygame collision with masks

The offset parameter of the method overlap() is the relative position of the othermask in relation to the pygame.mask.Mask object. So the offset is calculated by subtracting the coordinates of slant from the coordinates of ball: offset_x, offset_y = (slant.rect.x – ball.rect.x), (slant.rect.y – ball.rect.y) offset = (ball.rect.x – slant.rect.x), (ball.rect.y – slant.rect.y) if slant.mask.overlap(ball.mask, … Read more

How to detect when a rectangular object, image or sprite is clicked

If you’ve a sprite (my_sprite) and you want to verify if the mouse is on the sprite, then you’ve to get the .rect attribute of the pygame.sprite.Sprite object and to test if the mouse is in the rectangular area by .collidepoint(): mouse_pos = pygame.mouse.get_pos() if my_sprite.rect.collidepoint(mouse_pos): # […] The Sprites in a pygame.sprite.Group can iterate … Read more