From cef6e5cce7ab71f71178cc5ecba638512f0f0055 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 17 Mar 2024 22:28:10 +0100 Subject: [PATCH] implement power, WIP suit systems (defunct) --- src/hud.rs | 28 ++++++++++++++++++++++++---- src/player.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- src/settings.rs | 4 ++-- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/hud.rs b/src/hud.rs index 1f7cbae..44c99da 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -26,7 +26,7 @@ fn setup( settings: Res, asset_server: Res, ) { - let visibility = if settings.ar_active { + let visibility = if settings.hud_active { Visibility::Inherited } else { Visibility::Hidden @@ -51,7 +51,25 @@ fn setup( } ), TextSection::new( - "\n OXYGEN ", + "\n 电量 ", + TextStyle { + font: asset_server.load(FONT), + font_size: settings.font_size_hud, + color: Color::GRAY, + ..default() + }, + ), + TextSection::new( + "", + TextStyle { + font: asset_server.load(FONT), + font_size: settings.font_size_hud, + color: Color::GRAY, + ..default() + } + ), + TextSection::new( + "\n 氧 OXYGEN ", TextStyle { font: asset_server.load(FONT), font_size: settings.font_size_hud, @@ -109,10 +127,12 @@ fn update( text.sections[1].value = format!("{value:.0}"); } } + let power = playervars.power; + text.sections[3].value = format!("{power:}Wh"); let oxygen = playervars.oxygen * 100.0; - text.sections[3].value = format!("{oxygen:.1}%"); + text.sections[5].value = format!("{oxygen:.1}%"); let adrenaline = playervars.adrenaline * 990.0 + 10.0; - text.sections[5].value = format!("{adrenaline:.0}pg/mL"); + text.sections[7].value = format!("{adrenaline:.0}pg/mL"); } } } diff --git a/src/player.rs b/src/player.rs index ced91e9..85b1cc3 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,3 +1,4 @@ +use crate::settings; use bevy::prelude::*; use bevy::window::PrimaryWindow; @@ -18,11 +19,39 @@ impl Default for Player { } } +pub enum SuitSystemHandler { + Heat, + None, +} + +#[derive(Component)] +pub struct PlayerEntity; + +#[derive(Component)] +pub struct SuitSystem { + pub name: String, + pub active: bool, + pub power: f32, + pub handler: SuitSystemHandler, +} + +impl Default for SuitSystem { + fn default() -> Self { + Self { + name: "Untitled".to_string(), + active: true, + power: 0.0, + handler: SuitSystemHandler::None, + } + } +} + #[derive(Resource)] pub struct PlayerVars { pub oxygen: f32, pub adrenaline: f32, pub adrenaline_jolt: f32, + pub power: f32, } impl Default for PlayerVars { @@ -31,12 +60,30 @@ impl Default for PlayerVars { oxygen: 0.1984, adrenaline: 0.1, adrenaline_jolt: 0.5, + power: 6200.0, } } } -pub fn setup(mut commands: Commands) { +pub fn setup( + mut commands: Commands, + settings: Res, +) { commands.spawn(Player::default()); + commands.spawn(( + PlayerEntity, + SuitSystem { + name: "HUD".to_string(), + active: settings.hud_active, + power: -0.05, + ..default() + }, + SuitSystem { + name: "Heater".to_string(), + handler: SuitSystemHandler::Heat, + ..default() + } + )); } pub fn handle_input( diff --git a/src/settings.rs b/src/settings.rs index 044614f..f590317 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -9,7 +9,7 @@ pub struct Settings { pub font_size_hud: f32, pub font_size_conversations: f32, pub key_togglehud: KeyCode, - pub ar_active: bool, + pub hud_active: bool, } impl Default for Settings { @@ -22,7 +22,7 @@ impl Default for Settings { font_size_hud: 32.0, font_size_conversations: 32.0, key_togglehud: KeyCode::Tab, - ar_active: true, + hud_active: true, } } }