1
0
python-roguelike/render_functions.py

66 lines
1.6 KiB
Python
Raw Normal View History

2022-01-10 14:49:59 -05:00
from __future__ import annotations
from typing import Tuple, TYPE_CHECKING
2022-01-10 14:49:59 -05:00
import color
if TYPE_CHECKING:
from tcod import Console
2022-01-11 16:21:42 -05:00
from engine import Engine
from game_map import GameMap
def get_names_at_location(x: int, y: int, game_map: GameMap) -> str:
if not game_map.in_bounds(x, y) or not game_map.visible[x, y]:
return ""
names = ", ".join(
entity.name for entity in game_map.entities if entity.x == x and entity.y == y
)
return names.capitalize()
2022-01-10 14:49:59 -05:00
def render_bar(
2022-02-08 10:00:28 -05:00
console: Console,
current_value: int,
maximum_value: int,
total_width: int,
2022-01-10 14:49:59 -05:00
) -> None:
bar_width = int(float(current_value) / maximum_value * total_width)
console.draw_rect(x=0, y=45, width=20, height=1, ch=1, bg=color.bar_empty)
if bar_width > 0:
console.draw_rect(
2022-02-08 10:00:28 -05:00
x=0, y=45, width=bar_width, height=1, ch=1, bg=color.bar_filled
2022-01-10 14:49:59 -05:00
)
console.print(
x=1,
y=45,
string=f"HP: {current_value}/{maximum_value}",
fg=color.bar_text,
)
2022-01-11 16:21:42 -05:00
def render_dungeon_level(
2022-02-08 10:00:28 -05:00
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}")
2022-01-11 16:21:42 -05:00
def render_names_at_mouse_location(
2022-02-08 10:00:28 -05:00
console: Console, x: int, y: int, engine: Engine
2022-01-11 16:21:42 -05:00
) -> None:
mouse_x, mouse_y = engine.mouse_location
names_at_mouse_location = get_names_at_location(mouse_x, mouse_y, engine.game_map)
2022-02-08 10:00:28 -05:00
console.print(x, y, names_at_mouse_location)