Show hunger status

This commit is contained in:
Timothy Warren 2021-11-18 11:47:57 -05:00
parent 950c0a3ef1
commit 7b93ecc26c

View File

@ -1,4 +1,6 @@
use crate::components::{CombatStats, InBackpack, Name, Player, Position, Viewshed};
use crate::components::{
CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed,
};
use crate::{game_log::GameLog, Equipped, Map, RunState, State};
use rltk::{Point, Rltk, VirtualKeyCode, RGB};
use specs::prelude::*;
@ -15,9 +17,10 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
let combat_stats = ecs.read_storage::<CombatStats>();
let players = ecs.read_storage::<Player>();
let hunger = ecs.read_storage::<HungerClock>();
// Display player health
for (_player, stats) in (&players, &combat_stats).join() {
for (_player, stats, hc) in (&players, &combat_stats, &hunger).join() {
let health = format!(" HP: {} / {} ", stats.hp, stats.max_hp);
ctx.print_color(
12,
@ -36,6 +39,31 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
RGB::named(rltk::RED),
RGB::named(rltk::BLACK),
);
match hc.state {
HungerState::WellFed => ctx.print_color(
71,
42,
RGB::named(rltk::GREEN),
RGB::named(rltk::BLACK),
"Well Fed",
),
HungerState::Normal => {}
HungerState::Hungry => ctx.print_color(
71,
42,
RGB::named(rltk::ORANGE),
RGB::named(rltk::BLACK),
"Hungry",
),
HungerState::Starving => ctx.print_color(
71,
42,
RGB::named(rltk::RED),
RGB::named(rltk::BLACK),
"Well Fed",
),
}
}
let map = ecs.fetch::<Map>();