Navigate through different maps while climbing ladders
This commit is contained in:
parent
8636d571b5
commit
9a56b4d7e9
|
@ -55,7 +55,7 @@ class Game:
|
||||||
# TODO generate a new map procedurally
|
# TODO generate a new map procedurally
|
||||||
self.maps = []
|
self.maps = []
|
||||||
self.map_index = 0
|
self.map_index = 0
|
||||||
self.map = Map.load(ResourceManager.get_asset_path("example_map_2.txt"))
|
self.map = Map.load(ResourceManager.get_asset_path("example_map.txt"))
|
||||||
self.map.logs = self.logs
|
self.map.logs = self.logs
|
||||||
self.logs.clear()
|
self.logs.clear()
|
||||||
self.player = Player()
|
self.player = Player()
|
||||||
|
@ -102,6 +102,24 @@ class Game:
|
||||||
self.handle_key_pressed(
|
self.handle_key_pressed(
|
||||||
KeyValues.translate_key(key, self.settings), key)
|
KeyValues.translate_key(key, self.settings), key)
|
||||||
|
|
||||||
|
# FIXME This code should not be there, but rather in Map.tick
|
||||||
|
y, x = self.player.y, self.player.x
|
||||||
|
if self.map.tiles[y][x].is_ladder():
|
||||||
|
# We move up on the ladder of the beginning,
|
||||||
|
# down at the end of the stage
|
||||||
|
move_down = y != self.map.start_y and x != self.map.start_x
|
||||||
|
old_map = self.map
|
||||||
|
self.map_index += 1 if move_down else -1
|
||||||
|
self.map_index = max(0, self.map_index)
|
||||||
|
while self.map_index >= len(self.maps):
|
||||||
|
self.maps.append(Map.load(ResourceManager.get_asset_path(
|
||||||
|
"example_map_2.txt")))
|
||||||
|
new_map = self.map
|
||||||
|
old_map.remove_entity(self.player)
|
||||||
|
new_map.add_entity(self.player)
|
||||||
|
self.player.move(self.map.start_y, self.map.start_x)
|
||||||
|
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 = '')\
|
||||||
-> None:
|
-> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -140,10 +140,13 @@ class Map:
|
||||||
Put randomly {count} entities on the map, where it is available.
|
Put randomly {count} entities on the map, where it is available.
|
||||||
"""
|
"""
|
||||||
for ignored in range(count):
|
for ignored in range(count):
|
||||||
y, x = 0, 0
|
|
||||||
while True:
|
while True:
|
||||||
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
|
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
|
||||||
|
try:
|
||||||
tile = self.tiles[y][x]
|
tile = self.tiles[y][x]
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(y, x, len(self.tiles))
|
||||||
|
else:
|
||||||
if tile.can_walk():
|
if tile.can_walk():
|
||||||
break
|
break
|
||||||
entity = choice(Entity.get_all_entity_classes())()
|
entity = choice(Entity.get_all_entity_classes())()
|
||||||
|
|
Loading…
Reference in New Issue