mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added test gliding
Former-commit-id: 7aa1513511490feec531f10e58ad955c485ac594
This commit is contained in:
@ -7,6 +7,7 @@ pub enum InputEvent {
|
|||||||
pub struct Input {
|
pub struct Input {
|
||||||
pub move_dir: Vec2<f32>,
|
pub move_dir: Vec2<f32>,
|
||||||
pub jumping: bool,
|
pub jumping: bool,
|
||||||
|
pub gliding: bool,
|
||||||
pub events: Vec<InputEvent>,
|
pub events: Vec<InputEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ impl Default for Input {
|
|||||||
Input {
|
Input {
|
||||||
move_dir: Vec2::zero(),
|
move_dir: Vec2::zero(),
|
||||||
jumping: false,
|
jumping: false,
|
||||||
|
gliding: false,
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,7 @@ impl Client {
|
|||||||
comp::Control {
|
comp::Control {
|
||||||
move_dir: input.move_dir,
|
move_dir: input.move_dir,
|
||||||
jumping: input.jumping,
|
jumping: input.jumping,
|
||||||
|
gliding: input.gliding,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ impl Component for Agent {
|
|||||||
pub struct Control {
|
pub struct Control {
|
||||||
pub move_dir: Vec2<f32>,
|
pub move_dir: Vec2<f32>,
|
||||||
pub jumping: bool,
|
pub jumping: bool,
|
||||||
|
pub gliding: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Control {
|
impl Default for Control {
|
||||||
@ -25,6 +26,7 @@ impl Default for Control {
|
|||||||
Self {
|
Self {
|
||||||
move_dir: Vec2::zero(),
|
move_dir: Vec2::zero(),
|
||||||
jumping: false,
|
jumping: false,
|
||||||
|
gliding: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
// TODO: Don't hard-code this
|
// TODO: Don't hard-code this
|
||||||
// Apply physics to the player: acceleration and non-linear decceleration
|
// 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;
|
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 {
|
let animation = if on_ground {
|
||||||
|
@ -6,6 +6,7 @@ pub struct KeyState {
|
|||||||
pub up: bool,
|
pub up: bool,
|
||||||
pub down: bool,
|
pub down: bool,
|
||||||
pub jump: bool,
|
pub jump: bool,
|
||||||
|
pub glide: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyState {
|
impl KeyState {
|
||||||
@ -16,6 +17,7 @@ impl KeyState {
|
|||||||
up: false,
|
up: false,
|
||||||
down: false,
|
down: false,
|
||||||
jump: false,
|
jump: false,
|
||||||
|
glide: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ impl SessionState {
|
|||||||
Input {
|
Input {
|
||||||
move_dir,
|
move_dir,
|
||||||
jumping: self.key_state.jump,
|
jumping: self.key_state.jump,
|
||||||
|
gliding: self.key_state.glide,
|
||||||
events: input_events,
|
events: input_events,
|
||||||
},
|
},
|
||||||
dt,
|
dt,
|
||||||
@ -145,12 +146,14 @@ impl PlayState for SessionState {
|
|||||||
self.input_events.push(InputEvent::Jump);
|
self.input_events.push(InputEvent::Jump);
|
||||||
self.key_state.jump = true;
|
self.key_state.jump = true;
|
||||||
}
|
}
|
||||||
|
Event::KeyDown(Key::Glide) => self.key_state.glide = true,
|
||||||
// Movement Key Released
|
// Movement Key Released
|
||||||
Event::KeyUp(Key::MoveForward) => self.key_state.up = false,
|
Event::KeyUp(Key::MoveForward) => self.key_state.up = false,
|
||||||
Event::KeyUp(Key::MoveBack) => self.key_state.down = false,
|
Event::KeyUp(Key::MoveBack) => self.key_state.down = false,
|
||||||
Event::KeyUp(Key::MoveLeft) => self.key_state.left = false,
|
Event::KeyUp(Key::MoveLeft) => self.key_state.left = false,
|
||||||
Event::KeyUp(Key::MoveRight) => self.key_state.right = false,
|
Event::KeyUp(Key::MoveRight) => self.key_state.right = false,
|
||||||
Event::KeyUp(Key::Jump) => self.key_state.jump = 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
|
// Pass all other events to the scene
|
||||||
event => {
|
event => {
|
||||||
self.scene.handle_input_event(event);
|
self.scene.handle_input_event(event);
|
||||||
|
@ -25,6 +25,7 @@ pub struct ControlSettings {
|
|||||||
pub move_back: VirtualKeyCode,
|
pub move_back: VirtualKeyCode,
|
||||||
pub move_right: VirtualKeyCode,
|
pub move_right: VirtualKeyCode,
|
||||||
pub jump: VirtualKeyCode,
|
pub jump: VirtualKeyCode,
|
||||||
|
pub glide: VirtualKeyCode,
|
||||||
pub map: VirtualKeyCode,
|
pub map: VirtualKeyCode,
|
||||||
pub bag: VirtualKeyCode,
|
pub bag: VirtualKeyCode,
|
||||||
pub quest_log: VirtualKeyCode,
|
pub quest_log: VirtualKeyCode,
|
||||||
@ -60,6 +61,7 @@ impl Default for Settings {
|
|||||||
move_back: VirtualKeyCode::S,
|
move_back: VirtualKeyCode::S,
|
||||||
move_right: VirtualKeyCode::D,
|
move_right: VirtualKeyCode::D,
|
||||||
jump: VirtualKeyCode::Space,
|
jump: VirtualKeyCode::Space,
|
||||||
|
glide: VirtualKeyCode::LShift,
|
||||||
map: VirtualKeyCode::M,
|
map: VirtualKeyCode::M,
|
||||||
bag: VirtualKeyCode::B,
|
bag: VirtualKeyCode::B,
|
||||||
quest_log: VirtualKeyCode::L,
|
quest_log: VirtualKeyCode::L,
|
||||||
|
@ -46,6 +46,7 @@ impl Window {
|
|||||||
key_map.insert(settings.controls.move_back, Key::MoveBack);
|
key_map.insert(settings.controls.move_back, Key::MoveBack);
|
||||||
key_map.insert(settings.controls.move_right, Key::MoveRight);
|
key_map.insert(settings.controls.move_right, Key::MoveRight);
|
||||||
key_map.insert(settings.controls.jump, Key::Jump);
|
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.map, Key::Map);
|
||||||
key_map.insert(settings.controls.bag, Key::Bag);
|
key_map.insert(settings.controls.bag, Key::Bag);
|
||||||
key_map.insert(settings.controls.quest_log, Key::QuestLog);
|
key_map.insert(settings.controls.quest_log, Key::QuestLog);
|
||||||
@ -182,6 +183,7 @@ pub enum Key {
|
|||||||
MoveLeft,
|
MoveLeft,
|
||||||
MoveRight,
|
MoveRight,
|
||||||
Jump,
|
Jump,
|
||||||
|
Glide,
|
||||||
Enter,
|
Enter,
|
||||||
Escape,
|
Escape,
|
||||||
Map,
|
Map,
|
||||||
|
Reference in New Issue
Block a user