From 9c7cce4d3c9f910609fc7bc74fd8766356df5876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Dobrovoljc?= Date: Sun, 28 Jan 2024 17:08:30 +0100 Subject: [PATCH] Keypress detection fixes --- 10_2_slalom_v_d_molu/naloga.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/10_2_slalom_v_d_molu/naloga.py b/10_2_slalom_v_d_molu/naloga.py index bc7fbee..c4c07dd 100644 --- a/10_2_slalom_v_d_molu/naloga.py +++ b/10_2_slalom_v_d_molu/naloga.py @@ -35,9 +35,10 @@ class Player(GameObject): self.lives = 3 def update(self): - if pygame.K_LEFT in self.game.keys: + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: self.x -= 1 - if pygame.K_RIGHT in self.game.keys: + if keys[pygame.K_RIGHT]: self.x += 1 for obstacle in self.game.obstacles: @@ -102,7 +103,6 @@ class Game: self.running = True self.lost = False - self.keys = set() self.obstacles = [] self.points = 0 @@ -140,12 +140,6 @@ class Game: case pygame.QUIT: self.running = False break - case pygame.KEYDOWN: - self.keys.add(event.key) - break - case pygame.KEYUP: - self.keys.remove(event.key) - break if self.lost: return