state modifs

This commit is contained in:
2026-09-18 22:39:29 +02:00
parent 26448cd0a0
commit 8d496eee73
8 changed files with 64 additions and 98 deletions
+14 -10
View File
@@ -2,13 +2,13 @@ use bevy::prelude::*;
use crate::collision::check_collision_with_player;
use crate::collision::{Collider, HasCollided};
use crate::obstacle::RegenerateObstacles;
use crate::game_state::GameState;
const FALL_SPEED: f32 = 600.0; // Falling speed
const DIVE_SPEED: f32 = 1000.0; // Falling speed sped up
const HORIZONTAL_SPEED: f32 = 350.0; // Lateral movement speed
const HORIZONTAL_SPEED: f32 = 500.0; // Lateral movement speed
pub const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0); // Start position
const RATE: f32 = 13.0; // Inertia rate
// const RATE: f32 = 13.0; // Inertia rate
// The player
#[derive(Component)]
@@ -67,7 +67,7 @@ pub(crate) fn move_player(
0.0
};
let facteur = 1.0 - (-RATE * time.delta_secs()).exp();
// let facteur = 1.0 - (-RATE * time.delta_secs()).exp();
let target = Vec2::new(
direction * HORIZONTAL_SPEED,
-if input.pressed(KeyCode::KeyS) {
@@ -77,7 +77,8 @@ pub(crate) fn move_player(
},
);
velocity.0 = velocity.0.lerp(target, facteur);
// velocity.0 = velocity.0.lerp(target, facteur);
velocity.0 = target;
// Position update (no smoothness in velocity)
transform.translation += velocity.0.extend(0.0) * time.delta_secs();
@@ -89,7 +90,7 @@ pub fn reset_player(
input: Res<ButtonInput<KeyCode>>,
mut has_collided: ResMut<HasCollided>,
mut fall_started: ResMut<FallStarted>,
mut regenerate_obstacles: ResMut<RegenerateObstacles>,
// mut regenerate_obstacles: ResMut<RegenerateObstacles>,
) {
let (mut transform, mut velocity, mut sprite) = player.into_inner();
@@ -112,12 +113,15 @@ impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn_player)
.init_resource::<FallStarted>()
.add_systems(Update, move_player)
.add_systems(
Update,
reset_player
.after(move_player)
.after(check_collision_with_player),
(
move_player,
reset_player
.after(move_player)
.after(check_collision_with_player),
)
.run_if(in_state(GameState::InGame)),
);
}
}