I am trying to create a space invaders like game and have created the player and the firing mechanic. However, I am struggling with the asteroids as the collisions seem to be behaving incorrectly.
As shown here: https://gyazo.com/495dda6909b8436c98fea0d8ca55c6d0
My collision code:
def update(self, asteroids):
if self.rect.y > 0:
self.rect.y -= self.speed
else:
self.kill()
for asteroid in asteroids:
if self.rect.colliderect(asteroid.rect):
self.kill()
Adding a print message shows that the second kill command is being executed. I have no idea why this is occuring. Any help is appreciated. Thank you.
Edit: Yes, there is an asteroid and bullet sprite group. If you need the code, it is on my github. Here: https://github.com/RespectedCow/space-invaders
Edit: Fixed it. After printing the rect of the asteroid I figured out that the asteroid's size was configured after I did get_rect() on the surface, resulting in the rect being much larger than it should be thereby causing the issue. I simply moved the code that changes the surface's size on top of the code that got the rect from it.