Only refresh entities if the player moved, ignore most events

This commit is contained in:
Yohann D'ANELLO 2020-11-11 00:38:02 +01:00
parent 279d9d9f58
commit 5addd42535
1 changed files with 8 additions and 5 deletions

View File

@ -71,7 +71,6 @@ class Game:
self.display_refresh() self.display_refresh()
key = screen.getkey() key = screen.getkey()
self.handle_key_pressed(self.translate_key(key)) self.handle_key_pressed(self.translate_key(key))
self.map.tick()
def translate_key(self, key: str) -> KeyValues: def translate_key(self, key: str) -> KeyValues:
""" """
@ -112,13 +111,17 @@ class Game:
In play mode, arrows or zqsd should move the main character. In play mode, arrows or zqsd should move the main character.
""" """
if key == KeyValues.UP: if key == KeyValues.UP:
self.player.move_up() if self.player.move_up():
self.map.tick()
elif key == KeyValues.DOWN: elif key == KeyValues.DOWN:
self.player.move_down() if self.player.move_down():
self.map.tick()
elif key == KeyValues.LEFT: elif key == KeyValues.LEFT:
self.player.move_left() if self.player.move_left():
self.map.tick()
elif key == KeyValues.RIGHT: elif key == KeyValues.RIGHT:
self.player.move_right() if self.player.move_right():
self.map.tick()
elif key == KeyValues.SPACE: elif key == KeyValues.SPACE:
self.state = GameMode.MAINMENU self.state = GameMode.MAINMENU