From 0f6f2354d366256aba6abe2c85fe1f1d94ac4638 Mon Sep 17 00:00:00 2001 From: XsedoX Date: Thu, 28 Apr 2022 10:18:17 +0200 Subject: [PATCH] =?UTF-8?q?sprite=20group=20w=20level.py=20zamienilem=20na?= =?UTF-8?q?=20LayeredUpdates()=20oraz=20doda=C5=82em=20do=20ka=C5=BCdego?= =?UTF-8?q?=20sprite'a=20layer,=20wiec=20nie=20beda=20na=20siebie=20nachod?= =?UTF-8?q?zic=20nigdy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/game.py | 5 ++--- logic/level.py | 4 +++- models/castle.py | 1 + models/knight.py | 2 +- models/monster.py | 1 + models/tile.py | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/logic/game.py b/logic/game.py index 2643f1b..f738fe9 100644 --- a/logic/game.py +++ b/logic/game.py @@ -35,7 +35,7 @@ class Game: menu.display_screen() def game(self): - stats = Stats() + stats = Stats(self.screen) # setup clock for rounds NEXT_TURN = pygame.USEREVENT + 1 @@ -63,9 +63,8 @@ class Game: if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds self.level.handle_turn() - stats.draw(self.screen) + stats.draw() self.logs.draw() - self.level.update() if print_numbers_flag: diff --git a/logic/level.py b/logic/level.py index 7179f32..1a9a3a8 100644 --- a/logic/level.py +++ b/logic/level.py @@ -18,7 +18,7 @@ class Level: self.screen = screen self.logs = logs # sprite group setup - self.sprites = pygame.sprite.Group() + self.sprites = pygame.sprite.LayeredUpdates() self.map = [['g' for _ in range(COLUMNS)] for y in range(ROWS)] @@ -154,3 +154,5 @@ class Level: # update and draw the game self.sprites.draw(self.screen) + + diff --git a/models/castle.py b/models/castle.py index 629f524..04bffad 100644 --- a/models/castle.py +++ b/models/castle.py @@ -6,6 +6,7 @@ from common.helpers import parse_cord class Castle(pygame.sprite.Sprite): def __init__(self, position, group): super().__init__(group) + self._layer = 1 self.image = pygame.image.load("./resources/textures/castle.png").convert_alpha() self.image = pygame.transform.scale(self.image, (78, 78)) self.position = position diff --git a/models/knight.py b/models/knight.py index 6855328..0e264d1 100644 --- a/models/knight.py +++ b/models/knight.py @@ -28,6 +28,7 @@ class Knight(pygame.sprite.Sprite): self.image = self.states[self.direction.value] self.position = position + self._layer = 1 position_in_px = (parse_cord(position[0]), parse_cord(position[1])) self.rect = self.image.get_rect(topleft=position_in_px) @@ -37,7 +38,6 @@ class Knight(pygame.sprite.Sprite): self.defense = random.randint(1, 4) self.points = 1 self.health_bar = HealthBar(screen, self.rect, self.health, self.health) - self.health_bar.update() def rotate_left(self): self.direction = self.direction.left() diff --git a/models/monster.py b/models/monster.py index fa42177..0535896 100644 --- a/models/monster.py +++ b/models/monster.py @@ -14,6 +14,7 @@ monster_images = [ class Monster(pygame.sprite.Sprite): def __init__(self, position, group): super().__init__(group) + self._layer = 1 self.image = random.choice(monster_images) self.image = pygame.transform.scale(self.image, (40, 40)) position_in_px = (parse_cord(position[0]), parse_cord(position[1])) diff --git a/models/tile.py b/models/tile.py index ccbefa6..b6a7857 100644 --- a/models/tile.py +++ b/models/tile.py @@ -7,6 +7,7 @@ class Tile(pygame.sprite.Sprite): def __init__(self, position, image, group, tile_type=' '): super().__init__(group) self.image = image + self._layer = 0 position_in_px = (parse_cord(position[0]), parse_cord(position[1])) self.rect = self.image.get_rect(topleft=position_in_px) - self.tile_type = tile_type \ No newline at end of file + self.tile_type = tile_type