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)