Reset player
This commit is contained in:
+14
-2
@@ -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<Player>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user