draws entity hp bars above heads again

This commit is contained in:
Llywelwyn 2023-10-10 19:07:30 +01:00
parent 074e2465d7
commit 3c9eb2de27
3 changed files with 1047 additions and 1030 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Before After
Before After

View file

@ -297,17 +297,7 @@ fn draw_entities(
.size(TILESIZE.sprite_x, TILESIZE.sprite_y); .size(TILESIZE.sprite_x, TILESIZE.sprite_y);
if let Some(pool) = pools.get(entry.1.e) { if let Some(pool) = pools.get(entry.1.e) {
if pool.hit_points.current < pool.hit_points.max { if pool.hit_points.current < pool.hit_points.max {
gui::draw_bar( draw_entity_hp(x_pos, y_pos, pool, draw);
draw,
x_pos,
y_pos,
1.0,
1.0,
pool.hit_points.current,
pool.hit_points.max,
Color::GREEN,
Color::RED
);
} }
} }
} }
@ -317,6 +307,17 @@ fn draw_entities(
} }
} }
// Draws a HP bar LINE_WIDTH pixels thick centered above the entity.
fn draw_entity_hp(x: f32, y: f32, hp: &Pools, draw: &mut Draw) {
const LINE_WIDTH: f32 = 3.0;
let y = y + LINE_WIDTH + 1.0;
let x = x;
let fill_pct = (hp.hit_points.current as f32) / (hp.hit_points.max as f32);
draw.line((x + 1.0, y), (x + (TILESIZE.sprite_x - 1.0) * fill_pct, y))
.width(LINE_WIDTH)
.color(Color::GREEN);
}
fn render_map_in_view( fn render_map_in_view(
map: &Map, map: &Map,
ecs: &World, ecs: &World,