0

I'm making a top-down game in pygame, it's very basic right now and my coding experience/skill is limited, so I'm aware my code won't be flawless. Right now I have a character, and spawned zombies chase after him, but after a while they all merge into a single sprite image, and I can't figure out how to stop it.

From a guess I'm thinking I should use a for loop to check whether the zombie is colliding with other zombies, but I don't know how to do it, or whether it should be done from within the zombie class.

The code of the area where the zombie is moving is below, I'm not sure if the code for movement needs an overhaul for it to work, cause it's fairly primitive movement code.

thanks for any help guys,

Alex

def update(self):
    zx=self.rect.topleft[0]-player.rect[0]
    zy=self.rect.topleft[1]-player.rect[1]
    rads=math.atan2(-zy, zx)
    rads %= 2*pi
    angle = math.degrees(rads)
    self.rimage=pygame.transform.rotate(self.image, angle-90)
    size=self.rimage.get_size()

    if self.damaged:
        self.rimage=pygame.transform.rotate(self.image_damaged, angle-90)
        screen.blit(self.rimage, (self.rect.topleft[0]-size[0]/2,self.rect.topleft[1]-size[1]/2))
        print "oww"
        self.damaged=False


    if pygame.sprite.collide_circle(self, player):
        self.collidenumber += 1
    else:
        self.collidenumber = 0

    if self.collidenumber < 3:

        if player.rect[0]<self.rect[0]:
            self.rect[0]-=self.speed

        if player.rect[0]>self.rect[0]:
            self.rect[0]+=self.speed

        if player.rect[1]<self.rect[1]:
            self.rect[1]-=self.speed

        if player.rect[1]>self.rect[1]:
            self.rect[1]+=self.speedenter code here
Alex
  • 41
  • 4
  • 3
    This questions is a little broad for StackOverflow. It appears you're making good progress with the code and looking for general development strategies. If you can be more specific with your question (are you wanting to know how to do collision detection with the zombies? Are you looking for help on your movement code? Are you looking for whether or not the collision detection belongs in the zombie class?) this sight might help. Otherwise I would recommend trying http://gamedev.stackexchange.com or http://programmers.stackexchange.com – Pace May 06 '13 at 13:17
  • 2
    Are you asking how to keep the zombies from colliding, or how to keep their images from being drawn on top of each other? – Haz May 06 '13 at 13:31

0 Answers0