'Stairs' refers to a mechanism which, from a coding perspective, allows the player to move from one map to another. For example, in a traditional dungeon-crawling roguelike, stairs would move the player between levels, with each level being a different map.
stairs_upandstairs_downentities are drawn on the relevant maps- keyboard controls (
<and>) are added for taking stairs up/down - when the respective keyboard controls are pressed, a
TakeStairsActionis executed - the
TakeStairsActionchecks if the move is valid and, if so, the player moves from one map to another
In world_manager.py:
- Create two map entities and add them to the global_manager's
mapsdictionary.
map0 = world[object()]
map0.components[Tiles] = GROUND[np.random.randint(GROUND.size, size=(MAP_HEIGHT, MAP_WIDTH))]
global_manager.maps["map0"] = map0
map1 = world[object()]
map1.components[Tiles] = WATER[np.random.randint(WATER.size, size=(MAP_HEIGHT, MAP_WIDTH))]
global_manager.maps["map1"] = map1
- Create
stairs_upandstairs_downentities.
# Create a new entity.
stairs_up = world[object()]
# Add a position.
stairs_up.components[Position] = Position(55, 55)
# Add a graphic (ch, fg, bg).
stairs_up.components[Graphic] = Graphic(ord("<"), COLOR_BLACK, COLOR_MAGENTA)
# Add a custom tag, which the TakeStairs action will check during validation.
stairs_up.tags.add("up")
# Create a relationship between the stairs and the relevant map.
stairs_up.relation_tag[IsIn] = map1
stairs_down = world[object()]
stairs_down.components[Position] = Position(58, 58)
stairs_down.components[Graphic] = Graphic(ord(">"), COLOR_BLACK, COLOR_MAGENTA)
stairs_down.tags.add("down")
stairs_down.relation_tag[IsIn] = map0
In take_stairs_action.py, create a TakeStairsAction (also see the action documentation).
In play_state.py, in on_event() add the player keyboard controls for taking stairs up/down.
# > (. + shift) = take stairs down.
# < (, + shift) = take stairs up.
if event.mod & tcod.event.Modifier.SHIFT:
if event.sym == KeySym.PERIOD:
return do_action(player, TakeStairsAction("down"))
if event.sym == KeySym.COMMA:
return do_action(player, TakeStairsAction("up"))