diff --git a/src/actor.rs b/src/actor.rs index 548aca4..36c51e2 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -151,6 +151,8 @@ pub struct Engine { pub thrust_sideways: f32, pub reaction_wheels: f32, pub engine_type: EngineType, + pub warmup_seconds: f32, + pub current_warmup: f32, } impl Default for Engine { fn default() -> Self { @@ -160,6 +162,8 @@ impl Default for Engine { thrust_sideways: 1.0, reaction_wheels: 1.0, engine_type: EngineType::Monopropellant, + warmup_seconds: 1.5, + current_warmup: 0.0, } } } diff --git a/src/camera.rs b/src/camera.rs index ae8fc52..c9250e4 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -53,8 +53,15 @@ fn run_camera_controller( key_input: Res>, thruster_sound_controller: Query<&AudioSink, With>, rocket_sound_controller: Query<&AudioSink, With>, - q_engine: Query<&actor::Engine, With>, - mut query: Query<(&mut Transform, &mut CameraController, &mut Projection, &mut actor::Actor, &actor::LifeForm, &actor::Engine), With>, + mut q_engine: Query<&mut actor::Engine, With>, + mut query: Query<( + &mut Transform, + &mut CameraController, + &mut Projection, + &mut actor::Actor, + &actor::LifeForm, + &mut actor::Engine + ), (With, Without)>, ) { let dt = time.delta_seconds(); let mut play_thruster_sound = false; @@ -111,25 +118,28 @@ fn run_camera_controller( 0.0 }; + let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine }; + // Apply movement update if axis_input != Vec3::ZERO { let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed; controller.velocity = new_velocity; + engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); play_thruster_sound = !settings.mute_sfx; } else { controller.velocity *= 1.0 - friction; + engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); if controller.velocity.length_squared() < 1e-6 { controller.velocity = Vec3::ZERO; } } - let engine = if let Ok(engine) = q_engine.get_single() { engine } else { player_engine }; - let forward = *transform.forward() * (if axis_input.z > 0.0 { + let forward = *transform.forward() * engine.current_warmup * (if axis_input.z > 0.0 { engine.thrust_forward } else { engine.thrust_back }); - let right = *transform.right() * engine.thrust_sideways; + let right = *transform.right() * engine.thrust_sideways * engine.current_warmup; actor.v += controller.velocity.x * dt * right + controller.velocity.y * dt * Vec3::Y + controller.velocity.z * dt * forward; diff --git a/src/defs.txt b/src/defs.txt index b98ab7d..3c6c20b 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -80,7 +80,7 @@ actor 3650 230 5000 asteroid1 actor 10 -30 20 MeteorAceGT scale 5 vehicle yes - thrust 70 13.7 9.4 0.5 + thrust 70 13.7 9.4 0.5 20 engine rocket actor 10 0 70 suit diff --git a/src/world.rs b/src/world.rs index b3223c6..9d84d00 100644 --- a/src/world.rs +++ b/src/world.rs @@ -245,6 +245,7 @@ struct ParserState { thrust_sideways: f32, thrust_back: f32, reaction_wheels: f32, + warmup_seconds: f32, engine_type: actor::EngineType, oxygen: f32, @@ -284,6 +285,7 @@ impl Default for ParserState { thrust_sideways: default_engine.thrust_forward, thrust_back: default_engine.thrust_back, reaction_wheels: default_engine.reaction_wheels, + warmup_seconds: default_engine.warmup_seconds, engine_type: default_engine.engine_type, oxygen: nature::OXY_D, @@ -358,7 +360,9 @@ impl ParserState { thrust_back: self.thrust_back, thrust_sideways: self.thrust_sideways, reaction_wheels: self.reaction_wheels, + warmup_seconds: self.warmup_seconds, engine_type: self.engine_type, + ..default() }; let component_suit = actor::Suit { oxygen: self.oxygen, @@ -551,12 +555,13 @@ pub fn load_defs( continue; } } - ["thrust", forward, back, sideways, reaction_wheels] => { - if let (Ok(forward_float), Ok(back_float), Ok(sideways_float), Ok(reaction_wheels_float)) = (forward.parse::(), back.parse::(), sideways.parse::(), reaction_wheels.parse::()) { + ["thrust", forward, back, sideways, reaction_wheels, warmup_time] => { + if let (Ok(forward_float), Ok(back_float), Ok(sideways_float), Ok(reaction_wheels_float), Ok(warmup_time_float)) = (forward.parse::(), back.parse::(), sideways.parse::(), reaction_wheels.parse::(), warmup_time.parse::()) { state.thrust_forward = forward_float; state.thrust_back = back_float; state.thrust_sideways = sideways_float; state.reaction_wheels = reaction_wheels_float; + state.warmup_seconds = warmup_time_float; } } ["engine", "rocket"] => {