Render health bar
This commit is contained in:
parent
2d073a3839
commit
1d8539ee82
14
color.py
Normal file
14
color.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
white = (0xFF, 0xFF, 0xFF)
|
||||||
|
black = (0x0, 0x0, 0x0)
|
||||||
|
|
||||||
|
player_atk = (0xE0, 0xE0, 0xE0)
|
||||||
|
enemy_atk = (0xFF, 0xC0, 0xC0)
|
||||||
|
|
||||||
|
player_die = (0xFF, 0x30, 0x30)
|
||||||
|
enemy_die = (0xFF, 0xA0, 0x30)
|
||||||
|
|
||||||
|
welcome_text = (0x20, 0xA0, 0xFF)
|
||||||
|
|
||||||
|
bar_text = white
|
||||||
|
bar_filled = (0x0, 0x60, 0x0)
|
||||||
|
bar_empty = (0x40, 0x10, 0x10)
|
10
engine.py
10
engine.py
@ -7,6 +7,7 @@ from tcod.console import Console
|
|||||||
from tcod.map import compute_fov
|
from tcod.map import compute_fov
|
||||||
|
|
||||||
from input_handlers import MainGameEventHandler
|
from input_handlers import MainGameEventHandler
|
||||||
|
from render_functions import render_bar
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from entity import Actor
|
from entity import Actor
|
||||||
@ -39,10 +40,11 @@ class Engine:
|
|||||||
def render(self, console: Console, context: Context) -> None:
|
def render(self, console: Console, context: Context) -> None:
|
||||||
self.game_map.render(console)
|
self.game_map.render(console)
|
||||||
|
|
||||||
console.print(
|
render_bar(
|
||||||
x=1,
|
console,
|
||||||
y=47,
|
current_value=self.player.fighter.hp,
|
||||||
string=f"HP: {self.player.fighter.hp}/{self.player.fighter.max_hp}",
|
maximum_value=self.player.fighter.max_hp,
|
||||||
|
total_width=20,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Actually output to screen
|
# Actually output to screen
|
||||||
|
36
render_functions.py
Normal file
36
render_functions.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import color
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from tcod import Console
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user