Better teleport

This commit is contained in:
Yohann D'ANELLO 2020-12-26 21:13:17 +01:00
parent 6b7f8867fa
commit 663fc0eecd
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 16 additions and 2 deletions

View File

@ -110,14 +110,28 @@ class Game:
move_down = y != self.map.start_y and x != self.map.start_x move_down = y != self.map.start_y and x != self.map.start_x
old_map = self.map old_map = self.map
self.map_index += 1 if move_down else -1 self.map_index += 1 if move_down else -1
self.map_index = max(0, self.map_index) if self.map_index == -1:
self.map_index = 0
return
while self.map_index >= len(self.maps): while self.map_index >= len(self.maps):
self.maps.append(Map.load(ResourceManager.get_asset_path( self.maps.append(Map.load(ResourceManager.get_asset_path(
"example_map_2.txt"))) "example_map_2.txt")))
new_map = self.map new_map = self.map
old_map.remove_entity(self.player) old_map.remove_entity(self.player)
new_map.add_entity(self.player) new_map.add_entity(self.player)
if move_down:
self.player.move(self.map.start_y, self.map.start_x) self.player.move(self.map.start_y, self.map.start_x)
elif KeyValues.translate_key(key, self.settings) \
in [KeyValues.UP, KeyValues.DOWN,
KeyValues.LEFT, KeyValues.RIGHT]:
ladder_y, ladder_x = -1, -1
for y in range(self.map.height):
for x in range(self.map.width):
if (y, x) != (self.map.start_y, self.map.start_x) \
and self.map.tiles[y][x].is_ladder():
ladder_y, ladder_x = y, x
break
self.player.move(ladder_y, ladder_x)
self.display_actions(DisplayActions.UPDATE) self.display_actions(DisplayActions.UPDATE)
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\ def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\