Show inventory in hud
This commit is contained in:
parent
4aecf6f7d6
commit
580f51efdc
@ -3,12 +3,17 @@ use crate::prelude::*;
|
|||||||
#[system]
|
#[system]
|
||||||
#[read_component(Health)]
|
#[read_component(Health)]
|
||||||
#[read_component(Player)]
|
#[read_component(Player)]
|
||||||
|
#[read_component(Item)]
|
||||||
|
#[read_component(Carried)]
|
||||||
|
#[read_component(Name)]
|
||||||
pub fn hud(ecs: &SubWorld) {
|
pub fn hud(ecs: &SubWorld) {
|
||||||
let mut health_query = <&Health>::query().filter(component::<Player>());
|
let mut health_query = <&Health>::query().filter(component::<Player>());
|
||||||
let player_health = health_query.iter(ecs).next().unwrap();
|
let player_health = health_query.iter(ecs).next().unwrap();
|
||||||
let mut draw_batch = DrawBatch::new();
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
draw_batch.target(2);
|
draw_batch.target(2);
|
||||||
draw_batch.print_centered(1, "Explore the Dungeon. Cursor keys or ASWD to move.");
|
draw_batch.print_centered(1, "Explore the Dungeon. Cursor keys or ASWD to move.");
|
||||||
|
|
||||||
draw_batch.bar_horizontal(
|
draw_batch.bar_horizontal(
|
||||||
Point::zero(),
|
Point::zero(),
|
||||||
SCREEN_WIDTH * 2,
|
SCREEN_WIDTH * 2,
|
||||||
@ -24,5 +29,27 @@ pub fn hud(ecs: &SubWorld) {
|
|||||||
),
|
),
|
||||||
ColorPair::new(WHITE, RED),
|
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");
|
draw_batch.submit(10000).expect("Batch error");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user