From 8ed0ba71fea303068a54b517d59d4cf1da89d0a7 Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 12 Sep 2023 10:03:33 -0400 Subject: [PATCH] Tweaked values and changed cooldown from u64 to 128 --- src/comps/core/controller.rs | 2 +- src/constants/player_values.rs | 2 +- src/logic/core/player/player_movement.rs | 8 ++++---- src/logic/core/player/player_vertical_sync.rs | 4 ++-- src/logic/core/player/spawn_player.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/comps/core/controller.rs b/src/comps/core/controller.rs index e595393..436778c 100644 --- a/src/comps/core/controller.rs +++ b/src/comps/core/controller.rs @@ -10,7 +10,7 @@ pub fn capture_input(keyboard_input: Res>, query: Query<(&mut Vel // Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate. if keyboard_input.any_pressed([KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::W, KeyCode::C, KeyCode::Space]) { let player_movement_input = PlayerMovementInput { - up: keyboard_input.pressed(KeyCode::Space), + up: keyboard_input.just_pressed(KeyCode::Space), down: keyboard_input.pressed(KeyCode::C), left: keyboard_input.pressed(KeyCode::A), right: keyboard_input.pressed(KeyCode::D), diff --git a/src/constants/player_values.rs b/src/constants/player_values.rs index 82ec126..7de12c7 100644 --- a/src/constants/player_values.rs +++ b/src/constants/player_values.rs @@ -3,4 +3,4 @@ pub const MAX_LINEAR_PLAYER_VELOCITY: f32 = 10.0; pub const PLAYER_ACCELERATION: f32 = 10.0; pub const PLAYER_JUMP_FORCE: f32 = 1500.0; /// Time in ms that player must be grounded in order to jump again -pub const PLAYER_JUMP_COOLDOWN_MS: u64 = 300; \ No newline at end of file +pub const PLAYER_JUMP_COOLDOWN_MS: u128 = 100; \ No newline at end of file diff --git a/src/logic/core/player/player_movement.rs b/src/logic/core/player/player_movement.rs index cdaa696..ef621d8 100644 --- a/src/logic/core/player/player_movement.rs +++ b/src/logic/core/player/player_movement.rs @@ -5,17 +5,17 @@ use crate::{comps::core::markers::player::Player, constants::player_values::{MAX #[derive(Component)] pub enum PlayerLinearYState { - Grounded(u64), + Grounded(u128), Jumping, Falling } #[allow(unused)] impl PlayerLinearYState { - pub fn is_grounded(&self, longer_than: u64) -> bool { + pub fn is_grounded(&self, longer_than: &u128) -> bool { match self { Self::Grounded(time_grounded) => { - time_grounded > &longer_than + time_grounded > longer_than }, _ => false } @@ -81,7 +81,7 @@ pub fn move_player(player_movement_input: PlayerMovementInput, mut query: Query< player_velocity.linvel.x = apply_movement_acceleration(player_velocity.linvel.x, false, time.delta_seconds(), 1.0); } - if player_movement_input.up && player_linear_y_state.is_grounded(PLAYER_JUMP_COOLDOWN_MS) { + if player_movement_input.up && player_linear_y_state.is_grounded(&PLAYER_JUMP_COOLDOWN_MS) { player_external_force.impulse = Vec3::new(0.0, PLAYER_JUMP_FORCE, 0.0); *player_linear_y_state = PlayerLinearYState::Jumping; } diff --git a/src/logic/core/player/player_vertical_sync.rs b/src/logic/core/player/player_vertical_sync.rs index 7c5a6ca..54b2461 100644 --- a/src/logic/core/player/player_vertical_sync.rs +++ b/src/logic/core/player/player_vertical_sync.rs @@ -7,7 +7,7 @@ use super::player_movement::PlayerLinearYState; -/// System that captures input and fires events +/// System that captures linear y velocity and determines whether player is falling or grounded, and how long the player has been grounded for. pub fn sync_player_y_state(mut query: Query<(&Velocity, &mut PlayerLinearYState), With>, time: Res