2
1

2 Commits 326b6dcd94 ... b00bf24595

Autor SHA1 Nachricht Datum
  wullewutz b00bf24595 Fix inverted zoom direction vor 2 Jahren
  wullewutz 411eb48e6c KSP like main engine thrust controls vor 2 Jahren
4 geänderte Dateien mit 25 neuen und 12 gelöschten Zeilen
  1. 5 1
      README.md
  2. 5 0
      src/body.rs
  3. 2 2
      src/camera.rs
  4. 13 9
      src/ship.rs

+ 5 - 1
README.md

@@ -16,4 +16,8 @@ cargo run
 
 Use A and D to rotate ship.
 
-Use W to create forward thrust with the main engine.
+LeftShift to increase main engine thrust.
+LeftCtrl to decrease main engine thrust.
+X to shut down main engine completely.
+
+I/O or Mouseweel to zoom in/out.

+ 5 - 0
src/body.rs

@@ -9,3 +9,8 @@ pub struct Velocity {
 pub struct Rotation {
     pub r: f32, // radiants per second
 }
+
+#[derive(Component)]
+pub struct Thrust {
+    pub t: f32,
+}

+ 2 - 2
src/camera.rs

@@ -44,8 +44,8 @@ fn zoom_with_mousewheel(
     let mut projection = q.single_mut();
     for ev in scroll_evr.read() {
         match ev.unit {
-            MouseScrollUnit::Line => projection.scale += ZOOM_SPEED_WHEEL * ev.y,
-            MouseScrollUnit::Pixel => projection.scale += ZOOM_SPEED_WHEEL * ev.y,
+            MouseScrollUnit::Line => projection.scale -= ZOOM_SPEED_WHEEL * ev.y,
+            MouseScrollUnit::Pixel => projection.scale -= ZOOM_SPEED_WHEEL * ev.y,
         }
         projection.scale = projection.scale.clamp(0.2, 5000.);
     }

+ 13 - 9
src/ship.rs

@@ -1,4 +1,4 @@
-use crate::body::{Rotation, Velocity};
+use crate::body::{Rotation, Thrust, Velocity};
 use bevy::prelude::*;
 
 pub struct ShipsPlugin;
@@ -13,7 +13,7 @@ struct Name(String);
 struct TelemetryTimer(Timer);
 
 const RCS_THRUST: f32 = 0.5;
-const MAIN_THRUST: f32 = 1.0;
+const MAIN_THRUST: f32 = 0.1;
 
 impl Plugin for ShipsPlugin {
     fn build(&self, app: &mut App) {
@@ -39,27 +39,31 @@ fn spawn_ships(mut commands: Commands, asset_server: Res<AssetServer>) {
         Ship,
         Name("Player".to_string()),
         Velocity {
-            v: Vec3::new(0.0, 0.0, 0.0),
+            v: Vec3::new(0., 0., 0.),
         },
         Rotation {
             r: f32::to_radians(0.),
         },
+        Thrust { t: 0. },
     ));
 }
 
 fn apply_thrust(
     time: Res<Time>,
-    mut q: Query<(&mut Velocity, &mut Transform), With<Ship>>,
+    mut q: Query<(&mut Velocity, &mut Thrust, &mut Transform), With<Ship>>,
     keyboard: Res<Input<KeyCode>>,
 ) {
-    let mut thrust = Vec3::ZERO;
-    for (mut vel, mut trans) in &mut q {
+    for (mut vel, mut thr, mut trans) in &mut q {
         for k in keyboard.get_pressed() {
-            if k == &KeyCode::W {
-                thrust = (trans.rotation * Vec3::Y) * MAIN_THRUST * time.delta_seconds();
+            match k {
+                KeyCode::ShiftLeft => thr.t += MAIN_THRUST * time.delta_seconds(),
+                KeyCode::ControlLeft => thr.t -= MAIN_THRUST * time.delta_seconds(),
+                KeyCode::X => thr.t = 0.,
+                _ => (),
             }
         }
-        vel.v += thrust;
+        thr.t = thr.t.clamp(0., 100.);
+        vel.v += (trans.rotation * Vec3::Y) * thr.t;
         trans.translation += vel.v;
     }
 }