Keypress detection fixes
This commit is contained in:
parent
0c760d380c
commit
9c7cce4d3c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user