From 4bccf1ecfd712466306631e0a35f1dabfa6ea5a6 Mon Sep 17 00:00:00 2001 From: lbcmk <30442978+lbcmk@users.noreply.github.com> Date: Sat, 9 Jul 2022 03:28:25 -0400 Subject: [PATCH] Added a Dash Meter --- Game.py | 8 +++++++- UI/DashMeter.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 UI/DashMeter.py diff --git a/Game.py b/Game.py index 69d408a..d57ef0f 100644 --- a/Game.py +++ b/Game.py @@ -8,6 +8,7 @@ from Block import Block from PhysicsBody import PhysicsBody from World import World from EndScreen import EndScreen +from UI.DashMeter import DashMeter class Game: @@ -27,6 +28,7 @@ class Game: self.scene = EndScreen() + self.dashMeter = DashMeter() self.level = 1 self.scene.level = self.level @@ -55,10 +57,14 @@ class Game: self.player.draw(surf) - + self.dashMeter.update(self.player.lastDash, self.player.dashCooldown) + self.dashMeter.draw(surf) + if self.player.dead: self.scene.update() self.scene.draw() + + # 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) diff --git a/UI/DashMeter.py b/UI/DashMeter.py new file mode 100644 index 0000000..fef820a --- /dev/null +++ b/UI/DashMeter.py @@ -0,0 +1,32 @@ +from Setup import * +from CommonImports.colours import white +from Function.createText import createText +from datetime import datetime + +class DashMeter: + + def __init__(self): + self.texts = ['a'] + self.timeSinceLastDash = datetime.utcnow() + self.timer = self.timeSinceLastDash.second + self.timeSinceLastDash.microsecond / 100000 + + + def update(self, dash, cooldown): + 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 + + 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.center = ( + background_rect.centerx - 1080 * 0.185 * ((1 - self.timer * 0.4) / 2), background_rect.centery) + + pg.draw.rect(surf, (54, 54, 54), background_rect) + pg.draw.rect(surf, (175, 175, 175), foreground_rect) + + text_rect = self.texts[0].get_rect(center=background_rect.center) + surf.blit(self.texts[0], text_rect) -- 2.54.0