From: lbcmk <30442978+lbcmk@users.noreply.github.com> Date: Sat, 9 Jul 2022 07:46:42 +0000 (-0400) Subject: Updated the dash meter so it works when cooldown changes X-Git-Url: http://git.skullheadx.com/nixos/blog/static/gitweb.css?a=commitdiff_plain;h=095277c7faabb6b0b052201a8fb78330c0fa72dd;p=Pygame-Jam.git Updated the dash meter so it works when cooldown changes --- diff --git a/UI/DashMeter.py b/UI/DashMeter.py index fef820a..e1da4c9 100644 --- a/UI/DashMeter.py +++ b/UI/DashMeter.py @@ -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)