#coding: utf-8

import pygame

class Pilota(pygame.sprite.Sprite):
    
    def __init__(self, image, pos, vel):
        super(Pilota, self).__init__()
        self.image = image
        self.rect = self.image.get_rect()
        self.rect.center = pos
        self.dir = [-1, -1]
        self.vel = vel

    def update(self, ample, alt):
        despl = self.vel[0]*self.dir[0], self.vel[1]*self.dir[1]
        self.rect = self.rect.move(despl)
        self.actualitza_xoc_parets(ample, alt)

    def actualitza_xoc_parets(self, ample, alt):
        if self.rect.left < 0:
            self.dir[0] = 1
        elif self.rect.right >= ample:
            self.dir[0] = -1
        if self.rect.top < 0:
            self.dir[1] = 1
        elif self.rect.bottom > alt:
            self.dir[1] = -1

