diff --git a/src/player.rs b/src/player.rs index 3ab27ea..b6a9640 100644 --- a/src/player.rs +++ b/src/player.rs @@ -3,6 +3,7 @@ use bevy::prelude::*; 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); // The player #[derive(Component)] @@ -18,7 +19,7 @@ fn spawn_player(mut commands: Commands) { Player, Velocity(Vec2::ZERO), Sprite::from_color(Color::srgb(1.0, 1.0, 1.0), Vec2::new(20.0, 40.0)), - Transform::from_xyz(0.0, 0.0, 1.0), + Transform::from_xyz(START_POSITION.0, START_POSITION.1, START_POSITION.2), )); } @@ -54,11 +55,22 @@ pub(crate) fn move_player( transform.translation += velocity.0.extend(0.0) * time.delta_secs(); } +// Reset player position +fn reset_player( + mut player: Single<&mut Transform, With>, + input: Res>, +) { + if input.pressed(KeyCode::KeyR) { + player.translation = Vec3::new(START_POSITION.0, START_POSITION.1, START_POSITION.2); + } +} + pub struct PlayerPlugin; impl Plugin for PlayerPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, spawn_player) - .add_systems(Update, move_player); + .add_systems(Update, move_player) + .add_systems(Update, reset_player.after(move_player)); } }