import pygame


class Player(pygame.sprite.Sprite):

    def __init__(self,X,Y):
        super().__init__()
        self.sprite_sheet = pygame.image.load('MainCharacter.png')
        self.image = self.get_image(0,0)
        self.image.set_colorkey([0,0,0])
        self.rect = self.image.get_rect()
        self.position = [X, Y]
        self.images = {
            'down': self.get_image(0,0),
            'left': self.get_image(0,32),
            'right': self.get_image(0,64),
            'up': self.get_image(0,96)
        }

        self.speed = 2

    
    def changeAnimation(self, name): 
        """
        change animation celon direction
        """
        self.image = self.images[name]
        self.image.set_colorkey((0,0,0))


    
    def moveRight(self): 
        self.position[0] += self.speed
        
       
    
    def moveLeft(self): 
        self.position[0] -= self.speed    
    
    def moveUp(self): 
        self.position[1] -= self.speed
    
    def moveDown(self): 
        self.position[1] += self.speed                
    
    def update(self) -> None:
        self.rect.topleft = self.position

    def get_image(self,x,y):
        image = pygame.Surface([32,32])
        image.blit(self.sprite_sheet , (0,0), (x,y,32,32))
        return image