From: 711215 <711215@pdsb.net> Date: Wed, 13 Jul 2022 19:22:56 +0000 (-0400) Subject: boss health bar X-Git-Url: http://git.skullheadx.com/nixos/static/index.html?a=commitdiff_plain;h=b08393290be41aee4bd1f75e1e1256b7ce7d31ed;p=Pygame-Jam.git boss health bar --- diff --git a/Game.py b/Game.py index 200dfda..2915ff0 100644 --- a/Game.py +++ b/Game.py @@ -12,7 +12,7 @@ from Player import Player from Setup import * from Spike import Spike from UI.Dialogue import DialogueUI -from UI.HealthBar import HealthBar +from UI.HealthBar import BossHealthBar, HealthBar from UI.PotionUI import PotionUI from World import World from RangedAttack import RangedAttack @@ -66,6 +66,7 @@ class Game: # self.dashMeter = DashMeter(self.player.dashCooldown) self.healthBar = HealthBar() self.potionUI = PotionUI() + self.bosshealthBar = BossHealthBar() self.level = level self.scene.level = self.level @@ -189,6 +190,9 @@ class Game: if isinstance(particle, Cloud): del Setup.particles[Setup.particles.index(particle)] + if self.level == 4: + self.bosshealthBar.update() + # self.pet.update(delta, self.player, self.camera_pos) def draw(self, surf): @@ -308,6 +312,8 @@ class Game: # self.dashMeter.draw(surf) self.healthBar.draw(surf, self.player.health) self.potionUI.draw(surf, self.player.potion_bag, self.player.potion_cooldown) + if self.level == 4: + self.bosshealthBar.draw(surf, self.king.health) # print(self.player.get_collision_rect())s # Debug Lines. DO NOT CROSS THEM! # pg.draw.line(surf, (255, 0, 0), -Setup.camera_offset, pg.Vector2(SCREEN_WIDTH, -Setup.camera_offset.y), 10) diff --git a/UI/HealthBar.py b/UI/HealthBar.py index 819155c..e2f5f7e 100644 --- a/UI/HealthBar.py +++ b/UI/HealthBar.py @@ -8,6 +8,7 @@ class HealthBar: return; def update(self): + return; def draw(self, surf, health): @@ -28,3 +29,42 @@ class HealthBar: current_health_display = createText(0, 0, 30, white, "Regular", str(health) + "/100")[0] text_rect = current_health_display.get_rect(center=background_rect.center) surf.blit(current_health_display, text_rect) + +class BossHealthBar: + + def __init__(self): + self.bar_color = [255, 165, 0] + self.color_change = 0 + return; + + def update(self): + if self.color_change == 0 and self.bar_color[1] != 255: + self.bar_color[1] = self.bar_color[1] + 1 + if self.bar_color[1] == 255: + self.color_change = 1 + elif self.color_change == 1 and self.bar_color[1] != 0: + self.bar_color[1] -= 1 + if self.bar_color[1] == 0: + self.color_change = 0 + + return; + + def draw(self, surf, health): + # Healthbar Stuff + # bar is made of 2 rectanges, background which is just a simple rectange and foreground which goes on top and has a bit of math involved + background_rect = pg.Rect(0, 0, 1060, 640 * 0.16) + background_rect.center = ((SCREEN_WIDTH/2, 580)) + + # idea is that 1080*0.185 = size of bar at 100% hp, at lower hp you want to get a fraction of that which is why we multiply by (health*0.01) example: 70 hp * 0.01 = 0.7 + foreground_rect = pg.Rect(0, 0, 1040 * (health * 0.001), 640 * 0.12) + # make sure the red part health bar always sits on the left + # sets bar to center of background bar, then subtracts 1/2 of blank space to put it on the left + foreground_rect.center = ( + background_rect.centerx - 1040 * ((1 - health * 0.001) / 2), background_rect.centery) + pg.draw.rect(surf, (54, 54, 54), background_rect) + pg.draw.rect(surf, self.bar_color, foreground_rect) + + # text + current_health_display = createText(0, 0, 50, white, "Bold", "The Bone King")[0] + text_rect = current_health_display.get_rect(center=(background_rect.center)) + surf.blit(current_health_display, text_rect) \ No newline at end of file diff --git a/main.py b/main.py index c2819f4..ddad700 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ delta = 1000//fps # scene = TransitionScene() scene = DevLevelSelect() old_level = 0 -level =0 +level = 4 next_level = 0 # final_level = 6