-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
30 lines (24 loc) · 1.26 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pygame
class UI:
def __init__(self, surface):
self.display_surface = surface
#zdrowie
self.health_bar = pygame.image.load("./graphics/ui/health_bar.png").convert_alpha()
self.health_bar_topleft = (54, 39)
self.bar_max_width = 152
self.bar_height = 4
#monety
self.coin = pygame.image.load("./graphics/ui/coin.png").convert_alpha()
self.coin_rect = self.coin.get_rect(topleft=(50, 61))
self.font = pygame.font.Font("./graphics/ui/ARCADEPI.TTF", 30)
def show_health(self, current, full):
self.display_surface.blit(self.health_bar, (20, 10))
current_health_ratio = current / full
current_bar_width = self.bar_max_width * current_health_ratio
health_bar_rect = pygame.Rect(self.health_bar_topleft, (current_bar_width, self.bar_height))
pygame.draw.rect(self.display_surface, "red", health_bar_rect)
def show_coins(self, amount):
self.display_surface.blit(self.coin, self.coin_rect)
coin_amount_surf = self.font.render(str(amount), False, "#33323d")
coin_amount_rect = coin_amount_surf.get_rect(midleft=(self.coin_rect.right + 4, self.coin_rect.centery))
self.display_surface.blit(coin_amount_surf, coin_amount_rect)