1
0
python-roguelike/render_functions.py

62 lines
1.4 KiB
Python
Raw Normal View History

2022-01-10 14:49:59 -05:00
from __future__ import annotations
from typing import TYPE_CHECKING
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(
console: Console,
current_value: int,
maximum_value: int,
total_width: int,
) -> 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(
x=0,
y=45,
width=bar_width,
height=1,
ch=1,
bg=color.bar_filled
)
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_names_at_mouse_location(
console: Console,
x: int,
y: int,
engine: Engine
) -> None:
mouse_x, mouse_y = engine.mouse_location
names_at_mouse_location = get_names_at_location(mouse_x, mouse_y, engine.game_map)
console.print(x, y, names_at_mouse_location)