summaryrefslogtreecommitdiff
path: root/src/sliceitoff/player/player.py
blob: e9cb569db85bedd6b90b9902e121cfd512793926 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import pygame

from display import Scaling
from images import Images

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

class Player():
    def __init__(self, field = None):
        self.field = field
        self.position = (20_000, 14_000)
        self.direction = False
        self.lazer = False
        self.sprites = pygame.sprite.Group()
        self.updated = True

    def __update_sprites(self):
        self.sprites.empty()
        image = Images.surfaces['player_00']
        if self.direction:
             image = pygame.transform.rotate(image, 90)
        self.sprites.add(PlayerSprite(
                image,
                Scaling.scale_to_display(self.position) ))
        if not self.lazer:
            self.updated = False
        
    def set_position(self, pos):
        if not self.lazer:
            self.position = Scaling.scale_to_internal(pos)
        self.updated = True
        
    def get_sprites(self):
        if self.updated:
            self.__update_sprites()
        return self.sprites
        
    def set_lazer(self):
        # self.lazer = True
        # self.updated = True
        self.field.slice(self.position, self.direction, 1_000)

    def set_direction(self):
        if not self.lazer:
            self.direction = not self.direction
            self.updated = True

    def __del__(self):
        pass