-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_functions.py
75 lines (54 loc) · 2.1 KB
/
render_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from __future__ import annotations
from typing import Tuple, TYPE_CHECKING
import color
if TYPE_CHECKING:
from tcod import Console
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()
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=total_width, 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
)
def render_xp_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=46, width=total_width, height=1, ch=1, bg=color.xp_bar_empty)
if bar_width > 0:
console.draw_rect(
x=0, y=46, width=bar_width, height=1, ch=1, bg=color.xp_bar_filled
)
console.print(
x=1, y=46, string=f"XP: {current_value}/{maximum_value}", fg=color.xp_bar_text
)
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=x, y=y, string=f"Dungeon level: {dungeon_level}")
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(
x=mouse_x, y=mouse_y, game_map=engine.game_map
)
console.print(x=x, y=y, string=names_at_mouse_location)