Less complexity on the handle key function
This commit is contained in:
parent
41548504de
commit
887a190f11
|
@ -155,47 +155,53 @@ class Game:
|
||||||
elif key == KeyValues.WAIT:
|
elif key == KeyValues.WAIT:
|
||||||
self.map.tick()
|
self.map.tick()
|
||||||
elif key == KeyValues.LADDER:
|
elif key == KeyValues.LADDER:
|
||||||
# On a ladder, we switch level
|
self.handle_ladder()
|
||||||
y, x = self.player.y, self.player.x
|
|
||||||
if not self.map.tiles[y][x].is_ladder():
|
|
||||||
return
|
|
||||||
|
|
||||||
# We move up on the ladder of the beginning,
|
def handle_ladder(self) -> None:
|
||||||
# down at the end of the stage
|
"""
|
||||||
move_down = y != self.map.start_y and x != self.map.start_x
|
The player pressed the ladder key to switch map
|
||||||
old_map = self.map
|
"""
|
||||||
self.map_index += 1 if move_down else -1
|
# On a ladder, we switch level
|
||||||
if self.map_index == -1:
|
y, x = self.player.y, self.player.x
|
||||||
self.map_index = 0
|
if not self.map.tiles[y][x].is_ladder():
|
||||||
return
|
return
|
||||||
while self.map_index >= len(self.maps):
|
|
||||||
# TODO: generate a new map
|
|
||||||
self.maps.append(Map.load(ResourceManager.get_asset_path(
|
|
||||||
"example_map_2.txt")))
|
|
||||||
new_map = self.map
|
|
||||||
new_map.floor = self.map_index
|
|
||||||
old_map.remove_entity(self.player)
|
|
||||||
new_map.add_entity(self.player)
|
|
||||||
if move_down:
|
|
||||||
self.player.move(self.map.start_y, self.map.start_x)
|
|
||||||
self.logs.add_message(
|
|
||||||
_("The player climbs down to the floor {floor}.")
|
|
||||||
.format(floor=-self.map_index))
|
|
||||||
else:
|
|
||||||
# Find the ladder of the end of the game
|
|
||||||
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.logs.add_message(
|
|
||||||
_("The player climbs up the floor {floor}.")
|
|
||||||
.format(floor=-self.map_index))
|
|
||||||
|
|
||||||
self.display_actions(DisplayActions.UPDATE)
|
# 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
|
||||||
|
if self.map_index == -1:
|
||||||
|
self.map_index = 0
|
||||||
|
return
|
||||||
|
while self.map_index >= len(self.maps):
|
||||||
|
# TODO: generate a new map
|
||||||
|
self.maps.append(Map.load(ResourceManager.get_asset_path(
|
||||||
|
"example_map_2.txt")))
|
||||||
|
new_map = self.map
|
||||||
|
new_map.floor = self.map_index
|
||||||
|
old_map.remove_entity(self.player)
|
||||||
|
new_map.add_entity(self.player)
|
||||||
|
if move_down:
|
||||||
|
self.player.move(self.map.start_y, self.map.start_x)
|
||||||
|
self.logs.add_message(
|
||||||
|
_("The player climbs down to the floor {floor}.")
|
||||||
|
.format(floor=-self.map_index))
|
||||||
|
else:
|
||||||
|
# Find the ladder of the end of the game
|
||||||
|
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.logs.add_message(
|
||||||
|
_("The player climbs up the floor {floor}.")
|
||||||
|
.format(floor=-self.map_index))
|
||||||
|
|
||||||
|
self.display_actions(DisplayActions.UPDATE)
|
||||||
|
|
||||||
def handle_friendly_entity_chat(self, key: KeyValues) -> None:
|
def handle_friendly_entity_chat(self, key: KeyValues) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue