list_zombies = pygame.sprite.Group()
walls = pygame.sprite.Group()
class Zombie(pygame.sprite.Sprite):
def __init__(self, x, y, speed):
pygame.sprite.Sprite.__init__(self, list_zombies)
self.x = x
self.y = y
self.speed = zombie_speed
self.image = pygame.image.load("Zombie.png").convert()
self.rect = self.image.get_rect()
self.pos1 = self.x
self.pos2 = self.y
def update(self):
self.y += zombie_speed
def main(self, display):
self.update()
display.blit(zombie_image_copy, (self.x, self.y))
class Wall(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self, walls)
self.x = x
self.y = y
self.image = wall_image.convert()
self.rect = self.image.get_rect()
def main(display):
display.blit(wall_image, (-100, 950))
main loop:
for zombie in list_zombies:
zombie.rect.topleft = (zombie.x, zombie.y)
if pygame.sprite.groupcollide(list_zombies, walls, 0, 0, collided= None):
zombie.kill()
These are my classes and i want to kill the zombie if it hits the wall. I have used groupcollide since spritecollide wouldn't work and I would get the error that Wall doesn't have the attribute rect. Somehow it is not working but also not giving me an error. Maybe you can help me.