0 Replies - 655 Views - Last Post: 11 May 2011 - 09:51 AM Rate Topic: -----

#1 SmS27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-May 11

How to have a sprite follow the user?

Posted 11 May 2011 - 09:51 AM

I have been attempting to have a sprite group(clouds) follow the user(plane) until a collision(which is 1 death). I have been looking around the web can't come up with a solution for the cloud class. (The plane is controlled by arrow keys not mouse pos). Everything is set up except the clouds homing in on the plane/user.

class Cloud(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("puff.gif")
        self.image = self.image.convert()
        self.rect = self.image.get_rect()
        self.reset()

        
    def update(self):
        self.rect.centerx += self.dx
        self.rect.centery += self.dy
        if self.rect.top > screen.get_height():
            self.reset()
        
    
    def reset(self):
         
        self.rect.bottom = 0
        self.rect.centerx = random.randrange(0, screen.get_width())
        p
        self.dy = random.randrange(5, 10)
        self.dx = random.randrange(-2, 2)


Is This A Good Question/Topic? 0
  • +

Page 1 of 1