-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth_bar.py
44 lines (38 loc) · 1.56 KB
/
health_bar.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
os.system("")
class HealthBar:
symbol_remaining: str = chr(9608)
symbol_lost: str = "_"
barrier = str = "|"
colors: dict = {
"red": "\033[91m",
"purple": "\33[95m",
"blue": "\33[34m",
"blue2": "\33[36m",
"blue3": "\33[96m",
"green": "\033[92m",
"green2": "\033[32m",
"brown": "\33[33m",
"yellow": "\33[93m",
"grey": "\33[37m",
"default": "\033[0m"
}
def __init__(self, entity, length: int= 20, is_colored: bool= True, color: str = "") -> None:
self.entity = entity
self.length = length
self.current_value = entity.health
self.max_value = entity.max_health
self.is_colored = is_colored
self.color = self.colors.get(color) or self.colors["default"]
def update(self) -> None:
self.current_value = self.entity.health
def draw(self) -> None:
remaining_bars = round(self.current_value / self.max_value * self.length)
lost_bars = self.length - remaining_bars
print(f"{self.entity.name}'s Health: {self.entity.health}/{self.entity.max_health}")
print(f"{self.barrier}"
f"{self.color if self.is_colored else ''}"
f"{remaining_bars * self.symbol_remaining}"
f"{lost_bars * self.symbol_lost}"
f"{self.colors['default'] if self.is_colored else ''}"
f"{self.barrier}")