1
0

Show the current dungeon level on the main interface

This commit is contained in:
Timothy Warren 2022-01-24 13:44:43 -05:00
parent 9e817cd103
commit 6462fe06ac
4 changed files with 30 additions and 4 deletions

View File

@ -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."""

View File

@ -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)

View File

@ -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,

View File

@ -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,