Compare commits
3 Commits
f36bce66e2
...
ae8b0c77a5
| Author | SHA1 | Date | |
|---|---|---|---|
| ae8b0c77a5 | |||
| afd1fcd6be | |||
| 3cd2ddbd46 |
7
game.py
7
game.py
@ -97,6 +97,8 @@ class Game(gameUtils.Game):
|
||||
self.timerStart = 0
|
||||
# Holds how much time the user has in total (not updated)
|
||||
self.timerLength = 0
|
||||
# The font used for the timer
|
||||
self.timerFont = pygame.font.SysFont('', 100)
|
||||
# Used for animating the red flash on the current character if the users enters it wrong.
|
||||
self.lastWrong = 0
|
||||
|
||||
@ -204,19 +206,22 @@ 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
|
||||
|
||||
# Draw the captcha progerss if there is a captcha
|
||||
if self.currentCaptcha is not None:
|
||||
x1 = self.size[0] / 2 - self.currentCaptchaImg.size[0] / 2
|
||||
y = self.size[1] / 2 + self.currentCaptchaImg.size[1] / 2
|
||||
x2 = x1 + (self.currentCaptcha.charIdx / len(self.currentCaptcha.chars)) * self.currentCaptchaImg.size[0]
|
||||
pygame.draw.line(self.surf, (0, 255, 0), (x1, y), (x2, y), 5)
|
||||
|
||||
if self.timerLength != 0:
|
||||
# Draw the timer if there's any time left
|
||||
timeLeft = self.timerLength - (time.perf_counter() - self.timerStart)
|
||||
if timeLeft > 0:
|
||||
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))
|
||||
self.surf.blit(self.timerFont.render(str(round(timeLeft, 1)), True, c), (0, 10))
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user