Better teleport
This commit is contained in:
parent
6b7f8867fa
commit
663fc0eecd
|
@ -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)
|
||||||
self.player.move(self.map.start_y, self.map.start_x)
|
if move_down:
|
||||||
|
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 = '')\
|
||||||
|
|
Loading…
Reference in New Issue