From 9aa9552499b9ee0fd3c3a4833640afbc45f8668e Mon Sep 17 00:00:00 2001 From: XsedoX Date: Fri, 29 Apr 2022 10:21:22 +0200 Subject: [PATCH] hp_bar pod tarczami liczony na podstawie hp knightow --- logic/game.py | 7 +++---- ui/stats.py | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/logic/game.py b/logic/game.py index 565a4cc..fe8cb28 100644 --- a/logic/game.py +++ b/logic/game.py @@ -26,7 +26,6 @@ class Game: self.bg = pygame.image.load("./resources/textures/bg.jpg") self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)} - def main_menu(self): menu = MainMenu(self.screen, self.clock, self.bg, self.game, @@ -37,7 +36,6 @@ class Game: def game(self): logs = Logs(self.screen) level = Level(self.screen, logs) - stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red) # setup clock for rounds NEXT_TURN = pygame.USEREVENT + 1 @@ -45,6 +43,9 @@ class Game: # create level level.create_map() + stats = Stats(self.screen, + level.list_knights_blue, + level.list_knights_red) # has to be called after level.create_map() print_numbers_flag = False running = True @@ -60,8 +61,6 @@ class Game: running = False if event.key == pygame.K_n: print_numbers_flag = not print_numbers_flag - if event.key == pygame.K_r: - stats.red_team_hp_bar.take_dmg(5) if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds level.handle_turn() diff --git a/ui/stats.py b/ui/stats.py index 9fee084..8d12156 100644 --- a/ui/stats.py +++ b/ui/stats.py @@ -15,8 +15,25 @@ class Stats: self.screen = screen self.x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15 self.y = 5 - self.blue_team_hp_bar = HealthBar(self.screen, pygame.Rect(self.x + 30, self.y + 210, 100, 15), current_hp=50, max_hp=100) - self.red_team_hp_bar = HealthBar(self.screen, pygame.Rect(self.x + 210, self.y + 210, 100, 15), 100, 100) + self.max_hp = 0 + self.blue_team_current_hp = 0 + self.red_team_current_hp = 0 + + for knight in list_knights_red: + self.max_hp += knight.max_hp + self.red_team_current_hp += knight.current_hp + + for knight in list_knights_blue: + self.blue_team_current_hp += knight.current_hp + + self.blue_team_hp_bar = HealthBar(self.screen, + pygame.Rect(self.x + 30, self.y + 210, 100, 15), + current_hp=self.blue_team_current_hp, + max_hp=self.max_hp) + self.red_team_hp_bar = HealthBar(self.screen, + pygame.Rect(self.x + 210, self.y + 210, 100, 15), + current_hp=self.red_team_current_hp, + max_hp=self.max_hp) def update(self): @@ -40,9 +57,9 @@ class Stats: # texts draw_text('Rycerze: ' + str(len(self.list_knights_blue)), FONT_DARK, self.screen, self.x + 35, self.y + 240, 18) # blue - draw_text('Fortece: ' + str(len(self.list_knights_red)), FONT_DARK, self.screen, self.x + 35, self.y + 270, 18) # red + draw_text('Fortece: 0', FONT_DARK, self.screen, self.x + 35, self.y + 270, 18) # red - draw_text('Rycerze: 4', FONT_DARK, self.screen, self.x + 215, self.y + 240, 18) + draw_text('Rycerze: ' + str(len(self.list_knights_red)), FONT_DARK, self.screen, self.x + 215, self.y + 240, 18) draw_text('Fortece: 0', FONT_DARK, self.screen, self.x + 215, self.y + 270, 18) # points