diff --git a/game.py b/game.py index c4df27a..0f2209f 100644 --- a/game.py +++ b/game.py @@ -1,5 +1,6 @@ from PIL import Image, ImageDraw, ImageFont import math as maths +import numpy as np import logging import pygame import gameUtils @@ -160,6 +161,10 @@ class Game(gameUtils.Game): for char, font in zip(captcha.chars, captcha.fonts): print(f'{char}: {font.path}') + # Start the timer + self.timerStart = time.perf_counter() + self.timerLength = random.randint(5, 10) + def onEvent(self, event): """ Ran when an event is fired. @@ -193,6 +198,14 @@ class Game(gameUtils.Game): self.surf.blit(gameUtils.centre(self.currentCaptchaImg, self.size)) #draws the text to center of the screen #TODO: actually scale the text, however, more work needs to be done on the actual function of the game first + if self.timerLength != 0: + timeLeft = self.timerLength - (time.perf_counter() - self.timerStart) + normalisedTimeLeft = max(timeLeft / self.timerLength, 0) + x = round((1-normalisedTimeLeft) * (self.size[0] // 2)) + w = normalisedTimeLeft * self.size[0] + c = np.round((255, 255*normalisedTimeLeft, 255*normalisedTimeLeft)) + pygame.draw.rect(self.surf, c, (x, 0, w, 10)) + def close(self): """ Ran when the game closes.