implemented boss health bar
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
This commit is contained in:
parent
64a3381eb9
commit
368b033aab
4 changed files with 51 additions and 3 deletions
Binary file not shown.
Binary file not shown.
52
classes.py
52
classes.py
|
|
@ -101,7 +101,7 @@ class Label():
|
|||
return
|
||||
with open(f'art/images/box/{self.sprite}', 'r') as tb:
|
||||
self.box = pygame.image.load(tb)
|
||||
self.box = pygame.transform.scale(self.box, (self.width,self.height))
|
||||
self.box = pygame.transform.scale(self.box, (self.width, self.height))
|
||||
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
|
||||
self.labelSurf = self.font.render(self.text, True, self.font_color)
|
||||
self.box.blit(self.labelSurf, [
|
||||
|
|
@ -110,6 +110,50 @@ class Label():
|
|||
])
|
||||
screen.blit(self.box, self.labelRect)
|
||||
|
||||
class HealthBar(Label):
|
||||
def __init__(self, text, hp, x, y=8, width=256, height=24, font='simple', font_size=20, font_color='#e3d807', sprite='bossbar') -> None:
|
||||
super().__init__(x, y, width, height, text, font, font_size, font_color)
|
||||
self.text = text.capitalize()
|
||||
self.max = hp
|
||||
self.sprite = [f'{sprite}_empty.png', f'{sprite}_full.png', f'{sprite}_edge.png']
|
||||
self.box = []
|
||||
self.filling_should = self.width
|
||||
self.filling_is = self.filling_should
|
||||
self.rect = pygame.Rect(0, 0, 0, 0)
|
||||
self.percentage = 100
|
||||
for sprite in self.sprite:
|
||||
with open(f'art/images/box/{sprite}', 'r') as tb:
|
||||
tmp = pygame.image.load(tb)
|
||||
self.box.append(pygame.transform.scale(tmp, (width, height)))
|
||||
|
||||
def draw(self, screen):
|
||||
if self.hidden:
|
||||
return
|
||||
for i, sprite in enumerate(self.sprite):
|
||||
with open(f'art/images/box/{sprite}', 'r') as tb:
|
||||
if i != 1:
|
||||
self.box[i] = pygame.image.load(tb)
|
||||
self.box[i] = pygame.transform.scale(self.box[i], (self.width, self.height))
|
||||
else:
|
||||
self.box[i] = pygame.image.load(tb)
|
||||
if not self.filling_is <= self.filling_should:
|
||||
self.filling_is -= 1.5
|
||||
self.box[i] = pygame.transform.scale(self.box[i], (self.filling_is, self.height))
|
||||
|
||||
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
|
||||
self.labelSurf = self.font.render(f'{self.text}: {self.percentage}%', True, self.font_color)
|
||||
self.box[-1].blit(self.labelSurf, [
|
||||
self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2,
|
||||
self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2
|
||||
])
|
||||
for box in self.box:
|
||||
screen.blit(box, self.labelRect)
|
||||
|
||||
def update(self, objects):
|
||||
for mob in objects[1]:
|
||||
if isinstance(mob, Boss):
|
||||
self.percentage = mob.health / (self.max / 100)
|
||||
self.filling_should = self.width * (self.percentage / 100)
|
||||
|
||||
|
||||
class DropDown():
|
||||
|
|
@ -318,6 +362,7 @@ class Room(GameObjects):
|
|||
self.objects.append(self.doors)
|
||||
|
||||
def objectCreation(self, WIDTH, HEIGHT):
|
||||
self.objects[4] = [wall for wall in self.genWalls(WIDTH, HEIGHT)]
|
||||
if self.type != 'boss':
|
||||
self.objects[1] = [Skeleton('skeleton', random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 2, 200) for i in range(0,random.randint(2, 5))] + [Zombie('zombie', random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 25) for i in range(0,random.randint(2, 5))]
|
||||
npcs = [NPC('vivi', 100, 'people/vivi.png', 0, 400, 600),
|
||||
|
|
@ -327,7 +372,7 @@ class Room(GameObjects):
|
|||
self.objects[2] = [random.choice(npcs)]
|
||||
else:
|
||||
self.objects[1] = [Boss('reddy', 40, WIDTH / 2 - 16, HEIGHT /2 - 32, 50, 0.1, 1, 5, 5000)]
|
||||
self.objects[4] = [wall for wall in self.genWalls(WIDTH, HEIGHT)]
|
||||
self.objects[4].append(HealthBar(self.objects[1][0].name, self.objects[1][0].health, WIDTH / 2 - 128))
|
||||
return self.objects
|
||||
|
||||
|
||||
|
|
@ -450,7 +495,8 @@ class Convo(Label):
|
|||
['oldlady', 1, ['Oh, did you kill all the rats?', 'You must be the chosen one!', 'It would be nice if you would go and talk to the village elder.']],
|
||||
['elder', 0, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']],
|
||||
['elder', 1, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']],
|
||||
['vivi', 0, ['Wer bist du denn?', 'Aber du kannst gerne aus dem Fenster springen, solange es nicht in meinem Unterricht ist.']]
|
||||
['vivi', 0, ['Wer bist du denn?', 'Aber du kannst gerne aus dem Fenster springen, solange es nicht in meinem Unterricht ist.']],
|
||||
['fairy', 0, ['Hello fellow traveler.', 'I am Aurelia, a Whisperwind Fairy.', '''Do not worry about me. I won't harm anybody.''', 'You should still be careful around other fairies, many of them are insidious.', 'But fear not lonely traveller, I will help you survive.', 'Please take this spell for your further journey']]
|
||||
]
|
||||
|
||||
def draw(self, screen):
|
||||
|
|
|
|||
2
main.py
2
main.py
|
|
@ -92,6 +92,8 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
|
||||
for thing in objects[4]:
|
||||
thing.draw(screen)
|
||||
if isinstance(thing, HealthBar):
|
||||
thing.update(objects)
|
||||
|
||||
for weapon in objects[3]:
|
||||
weapon.update(objects)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue