|
use std::time::Duration;
|
|
|
|
use bevy::{ ecs::system::{ Query, Res, ResMut, Resource }, time::{ Time, Timer } };
|
|
|
|
use super::health::Health;
|
|
|
|
|
|
#[derive(Resource, Default)]
|
|
pub struct HungerTimer(Timer);
|
|
|
|
|
|
pub fn decrease_hunger(
|
|
time: Res<Time>,
|
|
mut hunger_timer: ResMut<HungerTimer>,
|
|
mut health_query: Query<&mut Health>
|
|
) {
|
|
|
|
hunger_timer.0.tick(time.delta());
|
|
|
|
if hunger_timer.0.just_finished() {
|
|
|
|
for mut health in &mut health_query {
|
|
|
|
health.hunger = health.hunger.saturating_sub(1);
|
|
|
|
if health.hunger == 0 {
|
|
health.current = health.current.saturating_sub(1);
|
|
}
|
|
}
|
|
|
|
hunger_timer.0.set_duration(Duration::from_secs(20));
|
|
|
|
hunger_timer.0.reset();
|
|
}
|
|
}
|
|
|