Skip to content

Commit

Permalink
optimise event handling
Browse files Browse the repository at this point in the history
- moved keymap iteration inside a conditional
  which checks for KEYDOWN events
  • Loading branch information
jriyyya authored and chimosky committed Jun 25, 2023
1 parent 42ce84c commit 876b2c7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ def run(self):
if event.type == pygame.QUIT:
return
# Manage jumps
for i, key in enumerate(self.keymap):
if event.type == pygame.KEYDOWN and event.key == key:
self.play_sound("jump")
self.guys[i].move()
if event.type == pygame.KEYDOWN:
for i, key in enumerate(self.keymap):
if event.key == key:
self.play_sound("jump")
self.guys[i].move()

# Assign speed as per score
self.speed = 7 + self.score // 8
Expand Down

0 comments on commit 876b2c7

Please sign in to comment.