WMICraft/ui/stats.py
2022-06-09 23:56:26 +02:00

68 lines
3.3 KiB
Python

import pygame
import time
from logic.health_bar import HealthBar
from common.colors import FONT_DARK, ORANGE, WHITE, RED
from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_SIZE, BORDER_WIDTH, BORDER_RADIUS
from common.helpers import draw_text
class Stats:
def __init__(self, screen, list_knights_blue, list_knights_red):
self.grid = []
self.list_knights_blue = list_knights_blue
self.list_knights_red = list_knights_red
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=sum([knight.get_current_hp() for knight in self.list_knights_blue]),
max_hp=sum([knight.get_max_hp() for knight in self.list_knights_blue]))
self.red_team_hp_bar = HealthBar(self.screen,
pygame.Rect(self.x + 210, self.y + 210, 100, 15),
current_hp=sum([knight.get_current_hp() for knight in self.list_knights_red]),
max_hp=sum([knight.get_max_hp() for knight in self.list_knights_red]))
self.blue_team_points = 0
self.red_team_points = 0
def update(self):
# background
pygame.draw.rect(self.screen, WHITE, pygame.Rect(self.x, self.y, 340, 450), 0, BORDER_RADIUS)
# title
draw_text('STATS', FONT_DARK, self.screen, self.x + 120, self.y + 10, 36)
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(self.x, self.y + 65, 340, 3))
# shields
shield_blue = pygame.image.load('./resources/textures/shield_blue.png')
shield_red = pygame.image.load('./resources/textures/shield_red.png')
self.screen.blit(shield_blue, (self.x + 20, self.y + 80))
self.screen.blit(shield_red, (self.x + 200, self.y + 80))
draw_text('VS', FONT_DARK, self.screen, self.x + 150, self.y + 120, 36)
# HP bars
self.red_team_hp_bar.take_dmg(self.red_team_hp_bar.current_hp -
sum([knight.get_current_hp() for knight in self.list_knights_red]))
self.blue_team_hp_bar.take_dmg(self.blue_team_hp_bar.current_hp -
sum([knight.get_current_hp() for knight in self.list_knights_blue]))
self.red_team_hp_bar.update()
self.blue_team_hp_bar.update()
# 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_red)), FONT_DARK, self.screen, self.x + 215, self.y + 240, 18)
# points
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(self.x, self.y + 390, 340, 3))
draw_text('PUNKTY: ' + str(self.blue_team_points), FONT_DARK, self.screen, self.x + 35, self.y + 408, 18, True)
draw_text('PUNKTY: ' + str(self.red_team_points), FONT_DARK, self.screen, self.x + 215, self.y + 408, 18, True)
def add_points(self, team, points):
if team == "blue":
self.blue_team_points += points
else:
self.red_team_points += points