I'm attempting to make a marble simulation in pygame (python 3.7.3) and am struggling to get collisions between marbles and components. The main issue is that the collision detection methods I've tried are not detecting the image but the whole rectangle.
class Marble(pygame.sprite.Sprite):
def __init__(self,x,y,vx,vy,display,colours,image,ax,ay=2):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = self.image.get_rect()
self.image.set_colorkey((0,0,0,255))
self.mask = pygame.mask.from_surface(self.image,255)
def detect_collision(self,components):
if pygame.sprite.spritecollide(self,components,False,pygame.sprite.collide_mask):
return True`
class Masked_Component(pygame.sprite.Sprite):
def __init__(self,x,y,start,end,image,function):
pygame.sprite.Sprite.__init__(self)
self.x = x
self.y = y
self.start = start
self.end = end
self.image = image
self.function = function
self.rect = self.image.get_rect()
self.image.set_colorkey((0,0,0,255))
self.mask = pygame.mask.from_surface(self.image,255)`
Any help would be appreciated and sorry for the messy code.