Added red flash when wrong

This commit is contained in:
2025-07-06 20:06:13 +01:00
parent 11b1dad78b
commit db7faca3d9

View File

@ -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
# Used for animating the red flash on the current character if the users enters it wrong.
self.lastWrong = 0
self.fonts = []
self.Drawsurface = Image.new("RGB",(800,220),(255,255,255))
@ -184,6 +186,8 @@ class Game(gameUtils.Game):
elif event.unicode != '' and event.unicode in alphabet:
correct, finished = self.currentCaptcha.match(event.unicode)
if not correct:
self.lastWrong = time.perf_counter()
print(correct)
if finished:
self.createCaptcha()
@ -194,7 +198,9 @@ class Game(gameUtils.Game):
game logic that should be ran once per frame in here.
"""
self.surf.fill((0, 0, 0)) #sets the background colour
r = 1 - min(time.perf_counter() - self.lastWrong, 1)
self.surf.fill((r * 255, 0, 0)) #sets the background colour
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