Added random delay to the firing

This commit is contained in:
2025-06-22 18:26:41 +01:00
parent decb36295d
commit c0727b2f02

View File

@ -19,8 +19,6 @@ class Game(gameUtils.Game):
# Don't remove this. It does important things. :3 # Don't remove this. It does important things. :3
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# TODO: Add a random delay between the spin and fire
# TODO: Utiles the following new sounds: # TODO: Utiles the following new sounds:
# gun-load: Should be played at the beginning of the game, # gun-load: Should be played at the beginning of the game,
# and should have an animation accompanying it. # and should have an animation accompanying it.
@ -80,13 +78,16 @@ class Game(gameUtils.Game):
self.playSound(self.gunShot) self.playSound(self.gunShot)
elif event.key == pygame.K_3: elif event.key == pygame.K_3:
self.playSound(self.gunSpin) self.playSound(self.gunSpin)
elif event.key == pygame.K_SPACE: elif event.key == pygame.K_SPACE and not self.awaitingTimeout("FireDelay"):
self.gun.playAnim('spin') self.gun.playAnim('spin')
elif event.type == gameUtils.AnimStart: elif event.type == gameUtils.AnimStart:
if event.objectID == self.gun.objectID and event.animationID == 'spin': if event.objectID == self.gun.objectID and event.animationID == 'spin':
self.playSound(self.gunSpin) self.playSound(self.gunSpin)
elif event.type == gameUtils.AnimFinish: elif event.type == gameUtils.AnimFinish:
if event.objectID == self.gun.objectID and event.animationID == 'spin': if event.objectID == self.gun.objectID and event.animationID == 'spin':
self.timeout("FireDelay",randint(0,2000)/1000)
elif event.type == gameUtils.Timeout:
self.shockScale += self.fire() #check if the user gets shot self.shockScale += self.fire() #check if the user gets shot
self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds