summaryrefslogtreecommitdiff
path: root/src/sliceitoff/player/player.py
blob: de490830bae55d882793b9d6bd0ed41798d7cb8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import pygame

from display import Scaling
from images import Images

DEBUG = os.getenv("DEBUG")

class PlayerSprite(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect()
        
    def update(self, pos = None):
        if pos:
            w, h = self.image.get_size()
            self.rect = self.image.get_rect().move(pos[0]-w//2,pos[1]-h//2)

class Player(pygame.sprite.LayeredUpdates):
    def __init__(self):
        super().__init__()
        self.position = (0,0)
        self.direction = True
        self.lazer = False
        image = Images.surfaces['player_00']
        self.add(PlayerSprite(image), layer = 0)
        image = pygame.transform.rotate(image, 90)
        self.add(PlayerSprite(image), layer = 1)

    def update(self, pos = None, direction = False, dt = 0):
        if not self.lazer:
            if direction:
                self.direction = not self.direction
                self.switch_layer(0,1)
            if pos:
                super().update(pos = pos)
                self.position = Scaling.scale_to_internal(pos)