use rusting_engine::prelude::*;
pub const MAX_HEALTH: i32 = 3;
pub const SAFE_SECONDS: f32 = 1.0;
pub fn health(scene: &mut GameScene<'_>) {
scene.once("health", |scene| {
scene.set_counter("health", MAX_HEALTH);
scene.set_counter("health_safe", 0);
});
if !scene.cooldown_ready("health_safe") {
return;
}
let hazards = scene.in_class("hazard");
if !scene
.touching("Player")
.iter()
.any(|name| hazards.contains(name))
{
return;
}
scene.start_cooldown("health_safe", SAFE_SECONDS);
scene.flash("Player");
if scene.add_to_counter("health", -1) <= 0 {
scene.restart();
}
}