Added red flash when wrong
This commit is contained in:
8
game.py
8
game.py
@ -97,6 +97,8 @@ class Game(gameUtils.Game):
|
|||||||
self.timerStart = 0
|
self.timerStart = 0
|
||||||
# Holds how much time the user has in total (not updated)
|
# Holds how much time the user has in total (not updated)
|
||||||
self.timerLength = 0
|
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.fonts = []
|
||||||
self.Drawsurface = Image.new("RGB",(800,220),(255,255,255))
|
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:
|
elif event.unicode != '' and event.unicode in alphabet:
|
||||||
correct, finished = self.currentCaptcha.match(event.unicode)
|
correct, finished = self.currentCaptcha.match(event.unicode)
|
||||||
|
if not correct:
|
||||||
|
self.lastWrong = time.perf_counter()
|
||||||
print(correct)
|
print(correct)
|
||||||
if finished:
|
if finished:
|
||||||
self.createCaptcha()
|
self.createCaptcha()
|
||||||
@ -194,7 +198,9 @@ class Game(gameUtils.Game):
|
|||||||
game logic that should be ran once per frame in here.
|
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
|
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
|
#TODO: actually scale the text, however, more work needs to be done on the actual function of the game first
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user