Don't call screen.getkey() at a wrong place

This commit is contained in:
Yohann D'ANELLO 2020-12-07 21:29:57 +01:00
parent 57fab7db51
commit 099508d4c0
1 changed files with 21 additions and 9 deletions

View File

@ -33,6 +33,7 @@ class Game:
Init the game.
"""
self.state = GameMode.MAINMENU
self.waiting_for_friendly_key = False
self.settings = Settings()
self.settings.load_settings()
self.settings.write_settings()
@ -86,6 +87,10 @@ class Game:
return
if self.state == GameMode.PLAY:
if self.waiting_for_friendly_key:
# The player requested to talk with a friendly entity
self.handle_friendly_entity_chat(key)
else:
self.handle_key_pressed_play(key)
elif self.state == GameMode.INVENTORY:
self.handle_key_pressed_inventory(key)
@ -118,21 +123,28 @@ class Game:
elif key == KeyValues.SPACE:
self.state = GameMode.MAINMENU
elif key == KeyValues.T:
self.handle_friendly_entity_chat()
# Wait for the direction of the friendly entity
self.waiting_for_friendly_key = True
def handle_friendly_entity_chat(self) -> None:
keykey = self.screen.getkey()
keykey = KeyValues.translate_key(keykey, self.settings)
if keykey == KeyValues.UP:
def handle_friendly_entity_chat(self, key: KeyValues) -> None:
"""
If the player is talking to a friendly entity, we get the direction
where the entity is, then we interact with it.
"""
if not self.waiting_for_friendly_key:
return
self.waiting_for_friendly_key = False
if key == KeyValues.UP:
xp = self.player.x
yp = self.player.y - 1
elif keykey == KeyValues.DOWN:
elif key == KeyValues.DOWN:
xp = self.player.x
yp = self.player.y + 1
elif keykey == KeyValues.LEFT:
elif key == KeyValues.LEFT:
xp = self.player.x - 1
yp = self.player.y
elif keykey == KeyValues.RIGHT:
elif key == KeyValues.RIGHT:
xp = self.player.x + 1
yp = self.player.y
else: