diff options
Diffstat (limited to 'src/sliceitoff/player/player.py')
-rw-r--r-- | src/sliceitoff/player/player.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/sliceitoff/player/player.py b/src/sliceitoff/player/player.py index 002594f..0103a81 100644 --- a/src/sliceitoff/player/player.py +++ b/src/sliceitoff/player/player.py @@ -1,14 +1,14 @@ +""" player.player - Player sprite group and actions """ import os import pygame -from random import randrange - from display import Scaling from text import Fonts DEBUG = os.getenv("DEBUG") class PlayerSprite(pygame.sprite.Sprite): + """ The slicing tool. There is 2 of these. Horizontal and vertical """ def __init__(self, image): super().__init__() self.image = image @@ -19,7 +19,8 @@ class PlayerSprite(pygame.sprite.Sprite): 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): +class Player(pygame.sprite.Group): + """ The slicer. Special sprite group that only list 1 sprite """ def __init__(self): super().__init__() self.position = (0,0) @@ -34,17 +35,23 @@ class Player(pygame.sprite.LayeredUpdates): ch.fill( color, special_flags = pygame.BLEND_RGBA_MULT) image.blit(ch,(0,y)) image = pygame.transform.scale_by(image, 1_200 * Scaling.factor) - self.add(PlayerSprite(image), layer = 0) image = pygame.transform.rotate(image, 90) - self.add(PlayerSprite(image), layer = 1) + self.add(PlayerSprite(image)) + image = pygame.transform.rotate(image, 90) + self.add(PlayerSprite(image)) - def update(self, pos = None, direction = False, **kwargs): + def update(self, pos = None, direction = False): + """ Updates the position and direction """ if self.lazer: direction = False pos = None - super().update(pos = pos, **kwargs) if direction: self.direction = not self.direction - self.switch_layer(0,1) if pos: self.position = Scaling.scale_to_internal(pos) + for sprite in super().sprites(): + sprite.update(pos = pos) + + def sprites(self): + """ Only list sprite of current direction for draw """ + return [super().sprites()[self.direction]] |