diff --git a/src/player.rs b/src/player.rs index 4d5ce78..346c1d9 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,9 +1,11 @@ use bevy::prelude::*; +use crate::collision::{Collider, HasCollided}; + const FALL_SPEED: f32 = 300.0; // Falling speed const DIVE_SPEED: f32 = 700.0; // Falling speed sped up const HORIZONTAL_SPEED: f32 = 300.0; // Lateral movement speed -const START_POSITION: (f32, f32, f32) = (0.0, 0.0, 1.0); +const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0); // Start position // The player #[derive(Component)] @@ -17,9 +19,12 @@ pub struct Velocity(Vec2); fn spawn_player(mut commands: Commands) { commands.spawn(( Player, + Collider { + size: Vec2::new(20.0, 40.0), + }, Velocity(Vec2::ZERO), Sprite::from_color(Color::srgb(1.0, 1.0, 1.0), Vec2::new(20.0, 40.0)), - Transform::from_xyz(START_POSITION.0, START_POSITION.1, START_POSITION.2), + Transform::from_xyz(START_POSITION.x, START_POSITION.y, START_POSITION.z), )); } @@ -52,6 +57,7 @@ pub(crate) fn move_player( }, ); + // Position update (no smoothness in velocity) transform.translation += velocity.0.extend(0.0) * time.delta_secs(); } @@ -59,12 +65,15 @@ pub(crate) fn move_player( fn reset_player( mut player: Single<(&mut Transform, &mut Sprite), With>, input: Res>, + mut has_collided: ResMut, ) { let (mut transform, mut sprite) = player.into_inner(); + // R key for reset if input.just_pressed(KeyCode::KeyR) { - transform.translation = Vec3::new(START_POSITION.0, START_POSITION.1, START_POSITION.2); - sprite.color = Color::WHITE + transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z); + sprite.color = Color::WHITE; + has_collided.0 = false; } }