use actual data for gauges

This commit is contained in:
yuni 2024-05-08 00:33:49 +02:00
parent c38fcaa8dd
commit 99c32ce516

View file

@ -97,7 +97,7 @@ enum Gauge {
Health,
Power,
Oxygen,
Fuel,
Integrity,
}
#[derive(Resource)]
@ -345,13 +345,13 @@ fn setup(
));
});
// HP/O2/Fuel/Power Gauges
// HP/O2/Suit Integrity/Power Gauges
let gauges_handle: Handle<Image> = asset_server.load("sprites/gauge_horizontal.png");
let gauges = [
("sprites/dashboard_highbeams.png", Gauge::Health),
("sprites/dashboard_highbeams.png", Gauge::Power),
("sprites/dashboard_highbeams.png", Gauge::Oxygen),
("sprites/dashboard_highbeams.png", Gauge::Fuel),
("sprites/dashboard_highbeams.png", Gauge::Integrity),
];
for (i, (sprite, gauge)) in gauges.iter().enumerate() {
let bar_length = if i == 0 { 196.0 } else { 128.0 };
@ -666,15 +666,20 @@ fn update_speedometer(
}
fn update_gauges(
q_player: Query<(&actor::HitPoints, &actor::Suit), With<actor::Player>>,
mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>,
settings: Res<var::Settings>,
) {
let player = q_player.get_single();
if player.is_err() { return; }
let (hp, suit) = player.unwrap();
for (mut style, mut bg, gauge, len) in &mut q_gauges {
let value = match gauge {
Gauge::Health => 0.9,
Gauge::Oxygen => 0.1,
Gauge::Fuel => 0.3,
Gauge::Power => 1.0,
let value: f32 = match gauge {
Gauge::Health => hp.current / hp.max,
Gauge::Oxygen => suit.oxygen / suit.oxygen_max,
Gauge::Integrity => suit.integrity,
Gauge::Power => suit.power / suit.power_max,
};
if value < 0.5 {
*bg = settings.hud_color_alert.into();