diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 22afdce..57d711a 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -46,7 +46,7 @@ use crate::consts::visuals::{ }; use crate::consts::{ TILESIZE, FONTSIZE, DISPLAYWIDTH }; use notan::prelude::*; -use notan::draw::{ Draw, DrawTextSection, DrawImages }; +use notan::draw::{ Draw, DrawTextSection, DrawImages, DrawShapes }; use std::collections::HashMap; use bracket_lib::prelude::*; use specs::prelude::*; @@ -112,7 +112,7 @@ pub fn draw_lerping_bar( } } -fn draw_bar( +fn draw_bar_sprite( draw: &mut Draw, atlas: &HashMap, sx: f32, @@ -138,6 +138,26 @@ fn draw_bar( pub const TEXT_FONT_MOD: i32 = 2; +pub fn draw_bar( + draw: &mut notan::draw::Draw, + x: f32, + y: f32, + width: f32, // Tiles + height: f32, // Px + current: i32, + max: i32, + full: Color, + empty: Color +) { + let fill: f32 = (f32::max(current as f32, 0.0) / (max as f32)) * width; + draw.line((x * TILESIZE, y * TILESIZE), ((x + fill) * TILESIZE, y * TILESIZE)) + .color(full) + .width(height); + draw.line(((x + fill) * TILESIZE, y * TILESIZE), ((x + width) * TILESIZE, y * TILESIZE)) + .color(empty) + .width(height); +} + pub fn draw_ui2( ecs: &World, draw: &mut Draw, @@ -162,6 +182,28 @@ pub fn draw_ui2( let row1 = 53.0 * TILESIZE; let row2 = row1 + TILESIZE; draw_bar( + draw, + 2.0, + 53.5, + 22.0, + TILESIZE, + stats.hit_points.current, + stats.hit_points.max, + Color::GREEN, + Color::BLACK + ); + draw_bar( + draw, + 2.0, + 54.5, + 22.0, + TILESIZE, + stats.mana.current, + stats.mana.max, + Color::BLUE, + Color::BLACK + ); + /*draw_bar_sprite( draw, atlas, 2.0 * TILESIZE, @@ -171,7 +213,7 @@ pub fn draw_ui2( stats.hit_points.max, "ui_hp" ); - draw_bar( + draw_bar_sprite( draw, atlas, 2.0 * TILESIZE, @@ -180,7 +222,7 @@ pub fn draw_ui2( stats.mana.current, stats.mana.max, "ui_mp" - ); + );*/ // Draw AC let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills); let mut armour_ac_bonus = 0; diff --git a/src/main.rs b/src/main.rs index 5f770fb..10e9dfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,31 +267,17 @@ fn draw_camera( ); if let Some(pool) = pools.get(entry.1.e) { if pool.hit_points.current < pool.hit_points.max { - // TODO: Draw HP bar. Callback, so it's always on top? - let fill: f32 = - f32::max(pool.hit_points.current as f32, 0.0) / - (pool.hit_points.max as f32); - draw.line( - ((entry.0.x as f32) * TILESIZE, (entry.0.y as f32) * TILESIZE), - ( - ((entry.0.x as f32) + fill) * TILESIZE, - (entry.0.y as f32) * TILESIZE, - ) - ) - .color(Color::GREEN) - .width(1.0); - draw.line( - ( - ((entry.0.x as f32) + fill) * TILESIZE, - (entry.0.y as f32) * TILESIZE, - ), - ( - ((entry.0.x as f32) + 1.0) * TILESIZE, - (entry.0.y as f32) * TILESIZE, - ) - ) - .color(Color::RED) - .width(1.0); + gui::draw_bar( + draw, + entry.0.x as f32, + entry.0.y as f32, + 1.0, + 1.0, + pool.hit_points.current, + pool.hit_points.max, + Color::GREEN, + Color::RED + ); } } } else {