From f9e76921ec70c6eefe96b68bbc84321b4ecc33e6 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 17 Mar 2024 23:49:50 +0100 Subject: [PATCH] generalize player into actor --- src/actor.rs | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/hud.rs | 37 ++++++++------- src/main.rs | 11 ++--- src/player.rs | 97 --------------------------------------- src/world.rs | 13 +++++- 5 files changed, 160 insertions(+), 122 deletions(-) create mode 100644 src/actor.rs diff --git a/src/actor.rs b/src/actor.rs new file mode 100644 index 0000000..9d306a4 --- /dev/null +++ b/src/actor.rs @@ -0,0 +1,124 @@ +use bevy::prelude::*; + +#[allow(unused)] pub const OXYGEN_USE_KG_PER_S: f32 = 1e-5; +#[allow(unused)] pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S; +#[allow(unused)] pub const OXY_M: f32 = OXYGEN_USE_KG_PER_S * 60.0; +#[allow(unused)] pub const OXY_H: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0; +#[allow(unused)] pub const OXY_D: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0 * 24.0; + +pub struct ActorPlugin; +impl Plugin for ActorPlugin { + fn build(&self, app: &mut App) { + app.add_systems(FixedUpdate, update); + } +} + +#[derive(Component)] +pub struct Actor { + pub hp: f32, + pub m: f32, // mass + pub pos: Vec3, // position + pub v: Vec3, // velocity + // TODO: rotation +} + +impl Default for Actor { + fn default() -> Self { + Self { + hp: 100.0, + m: 100.0, + pos: Vec3::ZERO, + v: Vec3::ZERO, + } + } +} + +#[derive(Component)] +pub struct LifeForm { + pub adrenaline: f32, + pub adrenaline_baseline: f32, + pub adrenaline_jolt: f32, +} +impl Default for LifeForm { fn default() -> Self { Self { + adrenaline: 0.3, + adrenaline_baseline: 0.3, + adrenaline_jolt: 0.0, +}}} + +#[derive(Component)] +pub struct Suit { + pub oxygen: f32, + pub power: f32, + pub oxygen_max: f32, + pub power_max: f32, +} +impl Default for Suit { fn default() -> Self { SUIT_SIMPLE } } + +const SUIT_SIMPLE: Suit = Suit { + power: 1e5, + power_max: 1e5, + oxygen: OXY_D, + oxygen_max: OXY_D, +}; + +pub fn update( + time: Res