From 3fce0a5b57c923ff4ad21eb258bd4f222b0cda57 Mon Sep 17 00:00:00 2001 From: XsedoX Date: Fri, 13 May 2022 10:37:00 +0200 Subject: [PATCH] uzycie sprite.Group.update() - gdy umrze sprite, to healthbar nie bedzie renderowany --- logic/level.py | 16 ++-------------- models/castle.py | 3 +++ models/knight.py | 3 +++ models/monster.py | 3 +++ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/logic/level.py b/logic/level.py index 00d2044..f8e5ee5 100644 --- a/logic/level.py +++ b/logic/level.py @@ -147,19 +147,6 @@ class Level: self.logs.enqueue_log(f'AI {current_knight.team}: Ruch w lewo.') self.map[knight_pos_y][knight_pos_x - 1] = current_knight.team_alias() - def update_health_bars(self): - for knight in self.list_knights_blue: - knight.health_bar.update() - - for knight in self.list_knights_red: - knight.health_bar.update() - - for monster in self.list_monsters: - monster.health_bar.update() - - for castle in self.list_castles: - castle.health_bar.update() - def update(self): bg_width = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH bg_height = (GRID_CELL_PADDING + GRID_CELL_SIZE) * ROWS + BORDER_WIDTH @@ -167,4 +154,5 @@ class Level: # update and draw the game self.sprites.draw(self.screen) - self.update_health_bars() # has to be called last + self.sprites.update() + \ No newline at end of file diff --git a/models/castle.py b/models/castle.py index 915b514..6484c63 100644 --- a/models/castle.py +++ b/models/castle.py @@ -18,3 +18,6 @@ class Castle(pygame.sprite.Sprite): self.max_hp = 80 self.current_hp = random.randint(1, self.max_hp) self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) + + def update(self): + self.health_bar.update() diff --git a/models/knight.py b/models/knight.py index 93432e1..05eabfc 100644 --- a/models/knight.py +++ b/models/knight.py @@ -43,6 +43,9 @@ class Knight(pygame.sprite.Sprite): self.direction = self.direction.left() self.image = self.states[self.direction.value] + def update(self): + self.health_bar.update() + def rotate_right(self): self.direction = self.direction.right() self.image = self.states[self.direction.value] diff --git a/models/monster.py b/models/monster.py index b8415f1..04d50ec 100644 --- a/models/monster.py +++ b/models/monster.py @@ -41,3 +41,6 @@ class Monster(pygame.sprite.Sprite): self.max_hp = 7 self.attack = 2 self.points = 2 + + def update(self): + self.health_bar.update()