From b2a6838709f1d589e89ba60b105c744fa6ed0c91 Mon Sep 17 00:00:00 2001 From: lbcmk <30442978+lbcmk@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:21:56 -0400 Subject: [PATCH] Healthbar --- UI/HealthBar.py | 14 ++++++++++++++ main.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/UI/HealthBar.py b/UI/HealthBar.py index 819155c..0d865b6 100644 --- a/UI/HealthBar.py +++ b/UI/HealthBar.py @@ -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 c2819f4..fedab21 100644 --- 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 -- 2.54.0