import pygame
 
class Pilota(pygame.sprite.Sprite):
 
    def __init__(self, posicio, velocitat, nom_fitxer_imatge):
        super().__init__() # constructor de classe Sprite
        self.image = pygame.image.load(nom_fitxer_imatge).convert_alpha()
        self.rect = self.image.get_rect()  # rectangle de la imatge
        self.rect.left = posicio[0]
        self.rect.top = posicio[1]
        self.velocitat = list(velocitat)
        self.mon = pygame.display.get_surface().get_rect() # Àrea on es mourà
 
    def update(self): # Actualitza posició i la velocitat de la pilota 
        self.rect.move_ip(self.velocitat)
        if self.rect.left < 0 or self.rect.right > self.mon.width:
            self.velocitat[0] = -self.velocitat[0]
        if self.rect.top < 0 or self.rect.bottom > self.mon.height:
            self.velocitat[1] = -self.velocitat[1]
