de-sprite hp bar
This commit is contained in:
parent
719cedf526
commit
d66bc0d746
2 changed files with 57 additions and 29 deletions
|
|
@ -46,7 +46,7 @@ use crate::consts::visuals::{
|
||||||
};
|
};
|
||||||
use crate::consts::{ TILESIZE, FONTSIZE, DISPLAYWIDTH };
|
use crate::consts::{ TILESIZE, FONTSIZE, DISPLAYWIDTH };
|
||||||
use notan::prelude::*;
|
use notan::prelude::*;
|
||||||
use notan::draw::{ Draw, DrawTextSection, DrawImages };
|
use notan::draw::{ Draw, DrawTextSection, DrawImages, DrawShapes };
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
@ -112,7 +112,7 @@ pub fn draw_lerping_bar(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_bar(
|
fn draw_bar_sprite(
|
||||||
draw: &mut Draw,
|
draw: &mut Draw,
|
||||||
atlas: &HashMap<String, Texture>,
|
atlas: &HashMap<String, Texture>,
|
||||||
sx: f32,
|
sx: f32,
|
||||||
|
|
@ -138,6 +138,26 @@ fn draw_bar(
|
||||||
|
|
||||||
pub const TEXT_FONT_MOD: i32 = 2;
|
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(
|
pub fn draw_ui2(
|
||||||
ecs: &World,
|
ecs: &World,
|
||||||
draw: &mut Draw,
|
draw: &mut Draw,
|
||||||
|
|
@ -162,6 +182,28 @@ pub fn draw_ui2(
|
||||||
let row1 = 53.0 * TILESIZE;
|
let row1 = 53.0 * TILESIZE;
|
||||||
let row2 = row1 + TILESIZE;
|
let row2 = row1 + TILESIZE;
|
||||||
draw_bar(
|
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,
|
draw,
|
||||||
atlas,
|
atlas,
|
||||||
2.0 * TILESIZE,
|
2.0 * TILESIZE,
|
||||||
|
|
@ -171,7 +213,7 @@ pub fn draw_ui2(
|
||||||
stats.hit_points.max,
|
stats.hit_points.max,
|
||||||
"ui_hp"
|
"ui_hp"
|
||||||
);
|
);
|
||||||
draw_bar(
|
draw_bar_sprite(
|
||||||
draw,
|
draw,
|
||||||
atlas,
|
atlas,
|
||||||
2.0 * TILESIZE,
|
2.0 * TILESIZE,
|
||||||
|
|
@ -180,7 +222,7 @@ pub fn draw_ui2(
|
||||||
stats.mana.current,
|
stats.mana.current,
|
||||||
stats.mana.max,
|
stats.mana.max,
|
||||||
"ui_mp"
|
"ui_mp"
|
||||||
);
|
);*/
|
||||||
// Draw AC
|
// Draw AC
|
||||||
let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills);
|
let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills);
|
||||||
let mut armour_ac_bonus = 0;
|
let mut armour_ac_bonus = 0;
|
||||||
|
|
|
||||||
36
src/main.rs
36
src/main.rs
|
|
@ -267,31 +267,17 @@ fn draw_camera(
|
||||||
);
|
);
|
||||||
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 {
|
||||||
// TODO: Draw HP bar. Callback, so it's always on top?
|
gui::draw_bar(
|
||||||
let fill: f32 =
|
draw,
|
||||||
f32::max(pool.hit_points.current as f32, 0.0) /
|
entry.0.x as f32,
|
||||||
(pool.hit_points.max as f32);
|
entry.0.y as f32,
|
||||||
draw.line(
|
1.0,
|
||||||
((entry.0.x as f32) * TILESIZE, (entry.0.y as f32) * TILESIZE),
|
1.0,
|
||||||
(
|
pool.hit_points.current,
|
||||||
((entry.0.x as f32) + fill) * TILESIZE,
|
pool.hit_points.max,
|
||||||
(entry.0.y as f32) * TILESIZE,
|
Color::GREEN,
|
||||||
)
|
Color::RED
|
||||||
)
|
);
|
||||||
.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue