Add creative mode toggle
This commit is contained in:
parent
aec3509107
commit
08f78ab453
1 changed files with 28 additions and 6 deletions
|
@ -49,6 +49,7 @@ pub struct WorldState {
|
|||
|
||||
pub up_speed: f32,
|
||||
pub sprinting: bool,
|
||||
pub creative: bool,
|
||||
}
|
||||
|
||||
impl WorldState {
|
||||
|
@ -388,6 +389,7 @@ impl WorldState {
|
|||
backward_pressed: false,
|
||||
left_pressed: false,
|
||||
right_pressed: false,
|
||||
creative: false,
|
||||
};
|
||||
|
||||
world_state.update_world_geometry(render_context);
|
||||
|
@ -530,7 +532,25 @@ impl WorldState {
|
|||
VirtualKeyCode::S => self.backward_pressed = pressed,
|
||||
VirtualKeyCode::A => self.left_pressed = pressed,
|
||||
VirtualKeyCode::D => self.right_pressed = pressed,
|
||||
VirtualKeyCode::Space if state == &ElementState::Pressed => self.up_speed = 0.6,
|
||||
VirtualKeyCode::F2 if pressed => self.creative = !self.creative,
|
||||
VirtualKeyCode::Space => {
|
||||
self.up_speed = if self.creative {
|
||||
if pressed {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
} else {
|
||||
0.6
|
||||
}
|
||||
}
|
||||
VirtualKeyCode::LShift if self.creative => {
|
||||
self.up_speed = if pressed {
|
||||
-1.0
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
VirtualKeyCode::LControl => self.sprinting = state == &ElementState::Pressed,
|
||||
_ => (),
|
||||
}
|
||||
|
@ -556,7 +576,7 @@ impl WorldState {
|
|||
|
||||
let up = Vector3::unit_y() * self.up_speed * speed * dt_seconds;
|
||||
new_position += up;
|
||||
if self.check_collision(new_position) {
|
||||
if !self.creative && self.check_collision(new_position) {
|
||||
new_position -= up;
|
||||
self.up_speed = 0.0;
|
||||
}
|
||||
|
@ -565,7 +585,7 @@ impl WorldState {
|
|||
let forward = Vector3::new(yaw_cos, 0.0, yaw_sin).normalize();
|
||||
let forward = forward * forward_speed as f32 * speed * dt_seconds;
|
||||
new_position += forward;
|
||||
if self.check_collision(new_position) {
|
||||
if !self.creative && self.check_collision(new_position) {
|
||||
new_position -= forward;
|
||||
}
|
||||
|
||||
|
@ -573,15 +593,17 @@ impl WorldState {
|
|||
let right = Vector3::new(-yaw_sin, 0.0, yaw_cos).normalize();
|
||||
let right = right * right_speed as f32 * speed * dt_seconds;
|
||||
new_position += right;
|
||||
if self.check_collision(new_position) {
|
||||
if !self.creative && self.check_collision(new_position) {
|
||||
new_position -= right;
|
||||
}
|
||||
|
||||
self.camera.position = new_position;
|
||||
|
||||
if !self.creative {
|
||||
self.up_speed -= 1.6 * dt.as_secs_f32();
|
||||
self.up_speed *= 0.98_f32.powf(dt.as_secs_f32() / 20.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, dt: Duration, render_context: &RenderContext) {
|
||||
self.update_position(dt);
|
||||
|
|
Loading…
Reference in a new issue