Keypress detection fixes

This commit is contained in:
Gašper Dobrovoljc 2024-01-28 17:08:30 +01:00
parent 0c760d380c
commit 9c7cce4d3c
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5

View File

@ -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