]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
boss health bar
author711215 <711215@pdsb.net>
Wed, 13 Jul 2022 19:22:56 +0000 (15:22 -0400)
committer711215 <711215@pdsb.net>
Wed, 13 Jul 2022 19:22:56 +0000 (15:22 -0400)
Game.py
UI/HealthBar.py
main.py

diff --git a/Game.py b/Game.py
index 200dfdae1dc50ba807e24098170ac341d4a7d7ee..2915ff0e01ea8af9f919924deac51f7f93c8e3aa 100644 (file)
--- 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)
index 819155ccf6daad4a1cac270bb363a77c2d31ad29..e2f5f7e9409f36d67866705c0452c918085a4217 100644 (file)
@@ -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 c2819f4ebb11f7604e7474569226456274bb5c79..ddad7005a7dcf7000ea8956f83a538142ad6ce13 100644 (file)
--- 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