I'm making a game where you throw snowballs at snowmen. Here are the definitions for the Snowman
class and Snowball
class:
class Snowman:
def __init__(self,start,end,a,b):
self.x = random.randrange(0,310)
self.y = 0
self.r = pygame.Rect(self.x,self.y,a,b)
class Snowball:
def __init__(self,a,b):
self.x = mousex
self.y = mousey
self.r = pygame.Rect(self.x,self.y,a,b)
As you can see, the r
attribute for the classes is their rectangle.
Below is a script that controls the snowman AI.
for s in snowmen:
s.y += 0.5
#above_makes_the_snowmen_approach_the_bottom_of_the_screen.
#below_is_supposed_to_check_for_snowball_collision.
for b in bullets:
if s.r.colliderect(b.r):
snowmen.remove(s)
bullets.remove(b)
print(b.r.colliderect(s.r))
#above_is_a_debugger_that_reports_the_collision.
if s.y < 640:
blit(asnowman,(50,78),(s.x,s.y))
else:
snowmen.remove(s)
The problem is when I throw a snowball at one of the snowmen, the debugger reports False
and the snowman doesn't die. How do I fix this?