Cargo fmt
This commit is contained in:
parent
f29eb34bcf
commit
b8fcb2d765
@ -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()
|
||||
|
@ -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()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<AssetServer>) {
|
||||
.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<AssetServer>) {
|
||||
.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,
|
||||
|
@ -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());
|
||||
|
@ -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<Cubemap>,
|
||||
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,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user