]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
Updated the dash meter so it works when cooldown changes
authorlbcmk <30442978+lbcmk@users.noreply.github.com>
Sat, 9 Jul 2022 07:46:42 +0000 (03:46 -0400)
committerlbcmk <30442978+lbcmk@users.noreply.github.com>
Sat, 9 Jul 2022 07:46:42 +0000 (03:46 -0400)
UI/DashMeter.py

index fef820a430582cea16b7d6816b7e6748491e2743..e1da4c99ad4222e6b5ecf1c210c207f0e3d76e2e 100644 (file)
@@ -5,25 +5,26 @@ from datetime import datetime
 
 class DashMeter:
 
-    def __init__(self):
+    def __init__(self, cooldown):
         self.texts = ['a']
         self.timeSinceLastDash = datetime.utcnow()
         self.timer = self.timeSinceLastDash.second + self.timeSinceLastDash.microsecond / 100000
+        self.cooldown = cooldown.seconds + cooldown.microseconds/1000000
 
         
-    def update(self, dash, cooldown):
+    def update(self, dash):
         self.timeSinceLastDash = datetime.utcnow() - dash
         self.timer = self.timeSinceLastDash.seconds + self.timeSinceLastDash.microseconds / 1000000
-        if(self.timer > cooldown.seconds + cooldown.microseconds/1000000):
-            self.timer = cooldown.seconds + cooldown.microseconds/1000000
+        if(self.timer > self.cooldown):
+            self.timer = self.cooldown
 
     def draw(self, surf):
         background_rect = pg.Rect(844, 20, 1080 * 0.2, 640 * 0.08)
-        foreground_rect = pg.Rect(0, 0, 1080 * 0.185 * (self.timer * 0.4), 640 * 0.06)
-        self.texts[0] = createText(0, 0, 30, white, "Regular", str(round(self.timer/0.025)) + "%")[0]
+        foreground_rect = pg.Rect(0, 0, 1080 * 0.185 * (self.timer/self.cooldown), 640 * 0.06)
+        self.texts[0] = createText(0, 0, 30, white, "Regular", str(round(self.timer/(self.cooldown/100))) + "%")[0]
 
         foreground_rect.center = (
-            background_rect.centerx - 1080 * 0.185 * ((1 - self.timer * 0.4) / 2), background_rect.centery)
+            background_rect.centerx - 1080 * 0.185 * ((1 - self.timer/self.cooldown) / 2), background_rect.centery)
 
         pg.draw.rect(surf, (54, 54, 54), background_rect)
         pg.draw.rect(surf, (175, 175, 175), foreground_rect)