hp_bar pod tarczami liczony na podstawie hp knightow

This commit is contained in:
XsedoX 2022-04-29 10:21:22 +02:00
parent 4ab8065879
commit 9aa9552499
2 changed files with 24 additions and 8 deletions

View File

@ -26,7 +26,6 @@ class Game:
self.bg = pygame.image.load("./resources/textures/bg.jpg") self.bg = pygame.image.load("./resources/textures/bg.jpg")
self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)} self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)}
def main_menu(self): def main_menu(self):
menu = MainMenu(self.screen, self.clock, self.bg, menu = MainMenu(self.screen, self.clock, self.bg,
self.game, self.game,
@ -37,7 +36,6 @@ class Game:
def game(self): def game(self):
logs = Logs(self.screen) logs = Logs(self.screen)
level = Level(self.screen, logs) level = Level(self.screen, logs)
stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red)
# setup clock for rounds # setup clock for rounds
NEXT_TURN = pygame.USEREVENT + 1 NEXT_TURN = pygame.USEREVENT + 1
@ -45,6 +43,9 @@ class Game:
# create level # create level
level.create_map() 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 print_numbers_flag = False
running = True running = True
@ -60,8 +61,6 @@ class Game:
running = False running = False
if event.key == pygame.K_n: if event.key == pygame.K_n:
print_numbers_flag = not print_numbers_flag 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 if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds
level.handle_turn() level.handle_turn()

View File

@ -15,8 +15,25 @@ class Stats:
self.screen = screen self.screen = screen
self.x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15 self.x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15
self.y = 5 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.max_hp = 0
self.red_team_hp_bar = HealthBar(self.screen, pygame.Rect(self.x + 210, self.y + 210, 100, 15), 100, 100) 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): def update(self):
@ -40,9 +57,9 @@ class Stats:
# texts # texts
draw_text('Rycerze: ' + str(len(self.list_knights_blue)), FONT_DARK, self.screen, self.x + 35, self.y + 240, 18) # blue 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) draw_text('Fortece: 0', FONT_DARK, self.screen, self.x + 215, self.y + 270, 18)
# points # points