From 7d36fbb5eea00e53fb05ffbdfff5a2d67bd4080e Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 13 May 2019 21:59:42 +0100 Subject: [PATCH] Added test gliding Former-commit-id: 7aa1513511490feec531f10e58ad955c485ac594 --- client/src/input.rs | 2 ++ client/src/lib.rs | 1 + common/src/comp/agent.rs | 2 ++ common/src/sys/control.rs | 4 ++++ voxygen/src/key_state.rs | 2 ++ voxygen/src/session.rs | 3 +++ voxygen/src/settings.rs | 2 ++ voxygen/src/window.rs | 2 ++ 8 files changed, 18 insertions(+) diff --git a/client/src/input.rs b/client/src/input.rs index 840ee46525..a274697e29 100644 --- a/client/src/input.rs +++ b/client/src/input.rs @@ -7,6 +7,7 @@ pub enum InputEvent { pub struct Input { pub move_dir: Vec2, pub jumping: bool, + pub gliding: bool, pub events: Vec, } @@ -15,6 +16,7 @@ impl Default for Input { Input { move_dir: Vec2::zero(), jumping: false, + gliding: false, events: Vec::new(), } } diff --git a/client/src/lib.rs b/client/src/lib.rs index 01da8675f2..cc44d1c6a8 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -156,6 +156,7 @@ impl Client { comp::Control { move_dir: input.move_dir, jumping: input.jumping, + gliding: input.gliding, }, ); diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index f3ff742700..1159316afc 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -18,6 +18,7 @@ impl Component for Agent { pub struct Control { pub move_dir: Vec2, pub jumping: bool, + pub gliding: bool, } impl Default for Control { @@ -25,6 +26,7 @@ impl Default for Control { Self { move_dir: Vec2::zero(), jumping: false, + gliding: false, } } } diff --git a/common/src/sys/control.rs b/common/src/sys/control.rs index c8ddf2d2cc..62ff038ee3 100644 --- a/common/src/sys/control.rs +++ b/common/src/sys/control.rs @@ -53,6 +53,10 @@ impl<'a> System<'a> for Sys { // TODO: Don't hard-code this // Apply physics to the player: acceleration and non-linear decceleration vel.0 += control.move_dir * 0.2 - vel.0.map(|e| e * e.abs() + e) * 0.002; + + if control.gliding && vel.0.z < 0.0 { + vel.0.z += 9.81 * 3.95 * dt.0; + } } let animation = if on_ground { diff --git a/voxygen/src/key_state.rs b/voxygen/src/key_state.rs index 22e666f0ba..909f1f3490 100644 --- a/voxygen/src/key_state.rs +++ b/voxygen/src/key_state.rs @@ -6,6 +6,7 @@ pub struct KeyState { pub up: bool, pub down: bool, pub jump: bool, + pub glide: bool, } impl KeyState { @@ -16,6 +17,7 @@ impl KeyState { up: false, down: false, jump: false, + glide: false, } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index b66d036118..a8c4b2c2d5 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -66,6 +66,7 @@ impl SessionState { Input { move_dir, jumping: self.key_state.jump, + gliding: self.key_state.glide, events: input_events, }, dt, @@ -145,12 +146,14 @@ impl PlayState for SessionState { self.input_events.push(InputEvent::Jump); self.key_state.jump = true; } + Event::KeyDown(Key::Glide) => self.key_state.glide = true, // Movement Key Released Event::KeyUp(Key::MoveForward) => self.key_state.up = false, Event::KeyUp(Key::MoveBack) => self.key_state.down = false, Event::KeyUp(Key::MoveLeft) => self.key_state.left = false, Event::KeyUp(Key::MoveRight) => self.key_state.right = false, Event::KeyUp(Key::Jump) => self.key_state.jump = false, + Event::KeyUp(Key::Glide) => self.key_state.glide = false, // Pass all other events to the scene event => { self.scene.handle_input_event(event); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 5a22ee9936..b8f9c8b97b 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -25,6 +25,7 @@ pub struct ControlSettings { pub move_back: VirtualKeyCode, pub move_right: VirtualKeyCode, pub jump: VirtualKeyCode, + pub glide: VirtualKeyCode, pub map: VirtualKeyCode, pub bag: VirtualKeyCode, pub quest_log: VirtualKeyCode, @@ -60,6 +61,7 @@ impl Default for Settings { move_back: VirtualKeyCode::S, move_right: VirtualKeyCode::D, jump: VirtualKeyCode::Space, + glide: VirtualKeyCode::LShift, map: VirtualKeyCode::M, bag: VirtualKeyCode::B, quest_log: VirtualKeyCode::L, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 9f5cdd44fb..0bd0241f13 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -46,6 +46,7 @@ impl Window { key_map.insert(settings.controls.move_back, Key::MoveBack); key_map.insert(settings.controls.move_right, Key::MoveRight); key_map.insert(settings.controls.jump, Key::Jump); + key_map.insert(settings.controls.glide, Key::Glide); key_map.insert(settings.controls.map, Key::Map); key_map.insert(settings.controls.bag, Key::Bag); key_map.insert(settings.controls.quest_log, Key::QuestLog); @@ -182,6 +183,7 @@ pub enum Key { MoveLeft, MoveRight, Jump, + Glide, Enter, Escape, Map,