diff --git a/src/constants/player_values.rs b/src/constants/player_values.rs index 7f4cb28..943f06e 100644 --- a/src/constants/player_values.rs +++ b/src/constants/player_values.rs @@ -18,4 +18,4 @@ pub const PLAYER_LINEAR_DAMPING_WHILE_JUMPING: f32 = 0.25; pub const PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER: f32 = 0.2; pub const PLAYER_LATERAL_ACCELERATION_MULTIPLIER: f32 = 1.0; -pub const PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS: u128 = 20; \ No newline at end of file +pub const PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS: u128 = 20; diff --git a/src/logic/core/player/player_movement.rs b/src/logic/core/player/player_movement.rs index f7322d2..fb3d708 100644 --- a/src/logic/core/player/player_movement.rs +++ b/src/logic/core/player/player_movement.rs @@ -5,7 +5,9 @@ use crate::{ comps::core::markers::player::Player, constants::player_values::{ MAX_LINEAR_PLAYER_VELOCITY, PLAYER_ACCELERATION, PLAYER_CROUCH_SPEED_MULTIPLIER, - PLAYER_JUMP_COOLDOWN_MS, PLAYER_JUMP_FORCE, PLAYER_SPRINT_SPEED_MULTIPLIER, PLAYER_LINEAR_DAMPING_WHILE_JUMPING, PLAYER_LATERAL_ACCELERATION_MULTIPLIER, PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER, + PLAYER_JUMP_COOLDOWN_MS, PLAYER_JUMP_FORCE, PLAYER_LATERAL_ACCELERATION_MULTIPLIER, + PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER, + PLAYER_LINEAR_DAMPING_WHILE_JUMPING, PLAYER_SPRINT_SPEED_MULTIPLIER, }, }; @@ -105,7 +107,7 @@ pub fn move_player( mut player_linear_y_state, mut player_linear_xz_state, player_transform, - mut player_damping + mut player_damping, ) in &mut query { let crouch_multiplier = if player_movement_input.down { @@ -191,7 +193,10 @@ pub fn move_player( 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; - *player_damping = Damping { linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING, ..Default::default()}; + *player_damping = Damping { + linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING, + ..Default::default() + }; } // When player velocity exceeds max linear velocity then set to max_linear_vel value if player_velocity.linvel.x.abs() diff --git a/src/logic/core/player/player_vertical_sync.rs b/src/logic/core/player/player_vertical_sync.rs index 81b66c9..a2c3182 100644 --- a/src/logic/core/player/player_vertical_sync.rs +++ b/src/logic/core/player/player_vertical_sync.rs @@ -1,7 +1,13 @@ use bevy::prelude::*; use bevy_rapier3d::prelude::*; -use crate::{comps::core::markers::player::Player, constants::player_values::{PLAYER_LINEAR_DAMPING, PLAYER_JUMP_COOLDOWN_MS, PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS, PLAYER_LINEAR_DAMPING_WHILE_JUMPING}}; +use crate::{ + comps::core::markers::player::Player, + constants::player_values::{ + PLAYER_JUMP_COOLDOWN_MS, PLAYER_LINEAR_DAMPING, + PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS, PLAYER_LINEAR_DAMPING_WHILE_JUMPING, + }, +}; use super::player_movement::PlayerLinearYState; @@ -13,7 +19,10 @@ pub fn sync_player_y_state( for (player_velocity, mut player_linear_y_state, mut player_damping) in &mut query { if player_velocity.linvel.y < -1.0 { *player_linear_y_state = PlayerLinearYState::Falling; - *player_damping = Damping { linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING, ..Default::default() }; + *player_damping = Damping { + linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING, + ..Default::default() + }; } else if player_velocity.linvel.y >= -1.0 && player_velocity.linvel.y <= 1.0 { let previous_grounded_time = match *player_linear_y_state { PlayerLinearYState::Grounded(grounded_for) => grounded_for, @@ -21,8 +30,13 @@ pub fn sync_player_y_state( }; let new_grounded_time = previous_grounded_time + time.delta().as_millis(); *player_linear_y_state = PlayerLinearYState::Grounded(new_grounded_time); - if new_grounded_time > PLAYER_JUMP_COOLDOWN_MS - PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS { - *player_damping = Damping { linear_damping: PLAYER_LINEAR_DAMPING, ..Default::default()}; + if new_grounded_time + > PLAYER_JUMP_COOLDOWN_MS - PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS + { + *player_damping = Damping { + linear_damping: PLAYER_LINEAR_DAMPING, + ..Default::default() + }; } } } diff --git a/src/logic/core/player/spawn_player.rs b/src/logic/core/player/spawn_player.rs index 94fde1e..0ef56a9 100644 --- a/src/logic/core/player/spawn_player.rs +++ b/src/logic/core/player/spawn_player.rs @@ -1,9 +1,12 @@ -use bevy::{prelude::*, core_pipeline::Skybox}; +use bevy::{core_pipeline::Skybox, prelude::*}; use bevy_rapier3d::prelude::*; use crate::{ comps::core::{camera::MainCamera, markers::player::Player}, - constants::player_values::{PLAYER_HEIGHT, PLAYER_INITIAL_WEIGHT, PLAYER_GRAVITY_SCALE, PLAYER_LINEAR_DAMPING}, scenes::scene1::skybox::{CUBEMAPS, Cubemap}, + constants::player_values::{ + PLAYER_GRAVITY_SCALE, PLAYER_HEIGHT, PLAYER_INITIAL_WEIGHT, PLAYER_LINEAR_DAMPING, + }, + scenes::scene1::skybox::{Cubemap, CUBEMAPS}, }; use super::player_movement::{PlayerLinearXZState, PlayerLinearYState}; @@ -19,7 +22,7 @@ pub fn spawn_player(mut commands: Commands, asset_server: Res) { .insert(Restitution::coefficient(0.0)) .insert(Friction { coefficient: 0.0, - combine_rule: CoefficientCombineRule::Multiply + combine_rule: CoefficientCombineRule::Multiply, }) .insert(TransformBundle { local: Transform::from_xyz(3.0, 5.0, 2.0), @@ -43,11 +46,13 @@ pub fn spawn_player(mut commands: Commands, asset_server: Res) { .insert(PlayerLinearYState::Falling) .insert(PlayerLinearXZState::Stopped); - commands.spawn(MainCamera).insert(Camera3dBundle { - transform: Transform::from_xyz(0.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), - ..Default::default() - }) - .insert(Skybox(skybox_handle.clone())); + commands + .spawn(MainCamera) + .insert(Camera3dBundle { + transform: Transform::from_xyz(0.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), + ..Default::default() + }) + .insert(Skybox(skybox_handle.clone())); commands.insert_resource(Cubemap { is_loaded: false, diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index 615fee1..53620df 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -11,7 +11,10 @@ use crate::{ }, }; -use super::{ground::spawn_ground, lighting::setup_lighting, obstacles::spawn_obstacles, skybox::asset_loaded}; +use super::{ + ground::spawn_ground, lighting::setup_lighting, obstacles::spawn_obstacles, + skybox::asset_loaded, +}; pub fn load_scene(application: &mut App) { application.insert_resource(MouseMovementSettings::default()); diff --git a/src/scenes/scene1/mod.rs b/src/scenes/scene1/mod.rs index 0ad140b..3c16ac2 100644 --- a/src/scenes/scene1/mod.rs +++ b/src/scenes/scene1/mod.rs @@ -3,4 +3,4 @@ pub mod init; pub mod ground; pub mod lighting; pub mod obstacles; -pub mod skybox; \ No newline at end of file +pub mod skybox; diff --git a/src/scenes/scene1/skybox.rs b/src/scenes/scene1/skybox.rs index 0efb29c..8f3678b 100644 --- a/src/scenes/scene1/skybox.rs +++ b/src/scenes/scene1/skybox.rs @@ -1,11 +1,15 @@ -use bevy::{prelude::*, render::{texture::CompressedImageFormats, render_resource::{TextureViewDescriptor, TextureViewDimension}}, core_pipeline::Skybox, asset::LoadState}; +use bevy::{ + asset::LoadState, + core_pipeline::Skybox, + prelude::*, + render::{ + render_resource::{TextureViewDescriptor, TextureViewDimension}, + texture::CompressedImageFormats, + }, +}; -pub const CUBEMAPS: &[(&str, CompressedImageFormats)] = &[ - ( - "skybox/skybox.png", - CompressedImageFormats::NONE, - ), -]; +pub const CUBEMAPS: &[(&str, CompressedImageFormats)] = + &[("skybox/skybox.png", CompressedImageFormats::NONE)]; #[derive(Resource)] pub struct Cubemap { @@ -19,12 +23,12 @@ pub fn asset_loaded( mut cubemap: ResMut, mut skyboxes: Query<&mut Skybox>, ) { - if !cubemap.is_loaded && asset_server.get_load_state(&cubemap.image_handle) == LoadState::Loaded { + if !cubemap.is_loaded && asset_server.get_load_state(&cubemap.image_handle) == LoadState::Loaded + { let image = images.get_mut(&cubemap.image_handle).unwrap(); // NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture, // so they appear as one texture. The following code reconfigures the texture as necessary. if image.texture_descriptor.array_layer_count() == 1 { - image.reinterpret_stacked_2d_as_array( image.texture_descriptor.size.height / image.texture_descriptor.size.width, ); @@ -40,4 +44,4 @@ pub fn asset_loaded( cubemap.is_loaded = true; } -} \ No newline at end of file +}