implement adrenaline_jolt

This commit is contained in:
yuni 2024-03-17 21:57:30 +01:00
parent c80fec0dd4
commit 41d97942de
2 changed files with 16 additions and 8 deletions

View file

@ -2,17 +2,19 @@ use crate::{settings, player};
use bevy::prelude::*;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
const HUD_REFRESH_TIME: f32 = 0.5;
const FONT: &str = "tmp/fonts/NotoSansSC-Thin.ttf";
pub struct OutFlyHudPlugin;
impl Plugin for OutFlyHudPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, (update, handle_input));
app.insert_resource(FPSUpdateTimer(Timer::from_seconds(0.25, TimerMode::Repeating)));
app.insert_resource(FPSUpdateTimer(
Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating)));
}
}
const FONT: &str = "tmp/fonts/NotoSansSC-Thin.ttf";
#[derive(Component)]
struct GaugesText;
@ -109,8 +111,8 @@ fn update(
}
let oxygen = playervars.oxygen * 100.0;
text.sections[3].value = format!("{oxygen:.1}%");
let adrenaline = playervars.adrenaline * 430.0;
text.sections[5].value = format!("{adrenaline:.1}ppm");
let adrenaline = playervars.adrenaline * 990.0 + 10.0;
text.sections[5].value = format!("{adrenaline:.0}pg/mL");
}
}
}

View file

@ -28,9 +28,9 @@ pub struct PlayerVars {
impl Default for PlayerVars {
fn default() -> Self {
Self {
oxygen: 1.0,
oxygen: 0.1984,
adrenaline: 0.1,
adrenaline_jolt: 0.1,
adrenaline_jolt: 0.5,
}
}
}
@ -60,6 +60,12 @@ pub fn handle_input(
pub fn drain_resources(
mut playervars:ResMut<PlayerVars>,
) {
playervars.adrenaline = (playervars.adrenaline - 0.0001).clamp(0.0, 1.0);
if playervars.adrenaline_jolt.abs() > 1e-3 {
playervars.adrenaline_jolt *= 0.99;
}
else {
playervars.adrenaline_jolt = 0.0
}
playervars.adrenaline = (playervars.adrenaline - 0.0001 + playervars.adrenaline_jolt * 0.01).clamp(0.0, 1.0);
playervars.oxygen = (playervars.oxygen - 0.000001).clamp(0.0, 1.0);
}