Show inventory in hud

This commit is contained in:
Daniel Lynn 2021-07-10 19:38:19 -05:00
parent 4aecf6f7d6
commit 580f51efdc

View File

@ -3,12 +3,17 @@ use crate::prelude::*;
#[system]
#[read_component(Health)]
#[read_component(Player)]
#[read_component(Item)]
#[read_component(Carried)]
#[read_component(Name)]
pub fn hud(ecs: &SubWorld) {
let mut health_query = <&Health>::query().filter(component::<Player>());
let player_health = health_query.iter(ecs).next().unwrap();
let mut draw_batch = DrawBatch::new();
draw_batch.target(2);
draw_batch.print_centered(1, "Explore the Dungeon. Cursor keys or ASWD to move.");
draw_batch.bar_horizontal(
Point::zero(),
SCREEN_WIDTH * 2,
@ -24,5 +29,27 @@ pub fn hud(ecs: &SubWorld) {
),
ColorPair::new(WHITE, RED),
);
let player = <(Entity, &Player)>::query()
.iter(ecs)
.find_map(|(entity, _player)| Some(*entity))
.unwrap();
let mut item_query = <(&Item, &Name, &Carried)>::query();
let mut y = 3;
item_query
.iter(ecs)
.filter(|(_, _, carried)| carried.0 == player)
.for_each(|(_, name, _)| {
draw_batch.print(Point::new(3, y), format!("{} : {}", y - 2, &name.0));
y += 1;
});
if y > 3 {
draw_batch.print_color(
Point::new(3, 2),
"Items carried",
ColorPair::new(YELLOW, BLACK),
);
}
draw_batch.submit(10000).expect("Batch error");
}