-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthBar.py
45 lines (26 loc) · 1.3 KB
/
HealthBar.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
45
import pygame
vec = pygame.math.Vector2
class HealthBar(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.load_animations()
self.health = 5
self.image = self.health_animations[self.health]
self.pos = vec(x, y)
def render(self, display):
display.blit(self.image, self.pos)
def takeDamage(self, damage):
self.health -= damage
if self.health < 0: self.health = 0
self.image = self.health_animations[self.health]
def Heal(self, heal):
self.health += damage
if self.health > 5: self.health = 5
self.image = self.health_animations[self.health]
def load_animations(self):
self.health_animations = [pygame.image.load("Images/WEED0.png").convert_alpha(),
pygame.image.load("Images/WEED1.png").convert_alpha(),
pygame.image.load("Images/WEED2.png").convert_alpha(),
pygame.image.load("Images/WEED3.png").convert_alpha(),
pygame.image.load("Images/WEED4.png").convert_alpha(),
pygame.image.load("Images/WEED5.png").convert_alpha()]