From 6462fe06ace7221a6991a8aa2acf2170c0e9a0cd Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 24 Jan 2022 13:44:43 -0500 Subject: [PATCH] Show the current dungeon level on the main interface --- engine.py | 12 +++++++++--- input_handlers.py | 6 ++++++ render_functions.py | 15 ++++++++++++++- setup_game.py | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/engine.py b/engine.py index c59feff..b5a390a 100644 --- a/engine.py +++ b/engine.py @@ -9,7 +9,7 @@ from tcod.map import compute_fov import exceptions from message_log import MessageLog -from render_functions import render_bar, render_names_at_mouse_location +import render_functions if TYPE_CHECKING: from entity import Actor @@ -49,14 +49,20 @@ class Engine: self.message_log.render(console=console, x=21, y=45, width=40, height=5) - render_bar( + render_functions.render_bar( console, current_value=self.player.fighter.hp, maximum_value=self.player.fighter.max_hp, total_width=20, ) - render_names_at_mouse_location(console, x=21, y=44, engine=self) + render_functions.render_dungeon_level( + console, + dungeon_level=self.game_world.current_floor, + location=(0, 47) + ) + + render_functions.render_names_at_mouse_location(console, x=21, y=44, engine=self) def save_as(self, filename: str) -> None: """Save this Engine instance as a compressed file.""" diff --git a/input_handlers.py b/input_handlers.py index db09e05..0067ce4 100644 --- a/input_handlers.py +++ b/input_handlers.py @@ -404,9 +404,15 @@ class MainGameEventHandler(EventHandler): action: Optional[Action] = None key = event.sym + modifier = event.mod player = self.engine.player + if key == tcod.event.K_PERIOD and modifier & ( + tcod.event.KMOD_LSHIFT | tcod.event.KMOD_RSHIFT + ): + return actions.TakeStairsAction(player) + if key in MOVE_KEYS: dx, dy = MOVE_KEYS[key] action = BumpAction(player, dx, dy) diff --git a/render_functions.py b/render_functions.py index 47e457d..b2581ff 100644 --- a/render_functions.py +++ b/render_functions.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import Tuple, TYPE_CHECKING import color @@ -49,6 +49,19 @@ def render_bar( ) +def render_dungeon_level( + console: Console, + dungeon_level: int, + location: Tuple[int, int] +) -> None: + """ + Render the level the player is currently on, at the given location. + """ + x, y = location + + console.print(x, y, string=f"Dungeon level: {dungeon_level}") + + def render_names_at_mouse_location( console: Console, x: int, diff --git a/setup_game.py b/setup_game.py index 3636288..a343a67 100644 --- a/setup_game.py +++ b/setup_game.py @@ -36,6 +36,7 @@ def new_game() -> Engine: engine = Engine(player) engine.game_world = GameWorld( + engine=engine, max_rooms=max_rooms, room_min_size=room_min_size, room_max_size=room_max_size,