]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
Healthbar
authorlbcmk <30442978+lbcmk@users.noreply.github.com>
Wed, 13 Jul 2022 19:21:56 +0000 (15:21 -0400)
committerlbcmk <30442978+lbcmk@users.noreply.github.com>
Wed, 13 Jul 2022 19:21:56 +0000 (15:21 -0400)
UI/HealthBar.py
main.py

index 819155ccf6daad4a1cac270bb363a77c2d31ad29..0d865b6f10a6bb87d23c76b8041e572ec9d62073 100644 (file)
@@ -5,6 +5,8 @@ from Function.createText import createText
 class HealthBar:
 
     def __init__(self):
+        self.oldHealth = 100
+        self.frame = 0
         return;
         
     def update(self):
@@ -19,11 +21,23 @@ class HealthBar:
         foreground_rect = pg.Rect(0, 0, 1080 * 0.185 * (health * 0.01), 640 * 0.06)
         # 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_rect2 = pg.Rect(0, 0, 1080 * 0.185 * (self.oldHealth * 0.01), 640 * 0.06)
+        if(self.oldHealth != health):
+            foreground_rect2 = pg.Rect(0, 0, 1080 * 0.185 * (self.oldHealth * 0.01), 640 * 0.06)
+            self.oldHealth -= 1
+
         foreground_rect.center = (
             background_rect.centerx - 1080 * 0.185 * ((1 - health * 0.01) / 2), background_rect.centery)
+        foreground_rect2.x = foreground_rect.x
+        foreground_rect2.y = foreground_rect.y
         pg.draw.rect(surf, (54, 54, 54), background_rect)
+        pg.draw.rect(surf, white, foreground_rect2)
         pg.draw.rect(surf, red, foreground_rect)
 
+        for i in range(10):
+            a = pg.Rect(foreground_rect.x + (1080 * 0.0185 * i), foreground_rect.y, 1080 * 0.002, 640 * 0.06)
+            pg.draw.rect(surf, (54, 54, 54), a)
         # text
         current_health_display = createText(0, 0, 30, white, "Regular", str(health) + "/100")[0]
         text_rect = current_health_display.get_rect(center=background_rect.center)
diff --git a/main.py b/main.py
index c2819f4ebb11f7604e7474569226456274bb5c79..fedab2163d749fe12ba99b05d7e111e6060a78d3 100644 (file)
--- a/main.py
+++ b/main.py
@@ -14,7 +14,7 @@ from DevLevelSelect import DevLevelSelect
 delta = 1000//fps
 # scene = Menu()
 # scene = TransitionScene()
-scene = DevLevelSelect()
+scene = Menu()
 old_level = 0
 level =0
 next_level = 0