]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
Added a Dash Meter
authorlbcmk <30442978+lbcmk@users.noreply.github.com>
Sat, 9 Jul 2022 07:28:25 +0000 (03:28 -0400)
committerlbcmk <30442978+lbcmk@users.noreply.github.com>
Sat, 9 Jul 2022 07:28:25 +0000 (03:28 -0400)
Game.py
UI/DashMeter.py [new file with mode: 0644]

diff --git a/Game.py b/Game.py
index 69d408a8eedddaca8eaf9f18bc1df7944aa628e1..d57ef0fa2b9bdeb0d9451bce3af61eed3a75bc30 100644 (file)
--- 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 (file)
index 0000000..fef820a
--- /dev/null
@@ -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)