Miguel can now look left and right

This commit is contained in:
2024-11-07 19:25:44 +02:00
parent ef375b2da8
commit cd3397603e

View File

@@ -20,7 +20,7 @@ enum Facing {
Right, Right,
} }
#[derive(Default, Component)] #[derive(Default, Component, LdtkEntity)]
pub(crate) struct Player { pub(crate) struct Player {
direction: Facing, direction: Facing,
} }
@@ -38,7 +38,7 @@ struct PlayerBundle {
} }
fn player_movement( fn player_movement(
mut query: Query<(&mut Velocity, &GroundDetection, &mut Player, &mut Transform), With<Player>>, mut query: Query<(&mut Velocity, &GroundDetection, &mut Player, &mut Sprite), With<Player>>,
input: Res<ButtonInput<KeyCode>>, input: Res<ButtonInput<KeyCode>>,
) { ) {
// let movement_direction = // let movement_direction =
@@ -53,21 +53,25 @@ fn player_movement(
// } else { // } else {
// return; // return;
// }; // };
for (mut velocity, ground_detection, mut player, mut p_transform) in &mut query { for (mut velocity, ground_detection, mut player, mut p_sprite) in &mut query {
// let Right = if input.pressed(KeyCode::KeyD) { 1. } else { 0. };
// let left = if input.pressed(KeyCode::KeyA) { 1. } else { 0. };
let right = if input.pressed(KeyCode::KeyD) { let right = if input.pressed(KeyCode::KeyD) {
player.direction = Facing::Right;
1. 1.
} else { } else {
0. 0.
}; };
let left = if input.pressed(KeyCode::KeyA) { let left = if input.pressed(KeyCode::KeyA) {
player.direction = Facing::Left;
1. 1.
} else { } else {
0. 0.
}; };
match player.direction {
Facing::Right => {p_sprite.flip_x = false;},
Facing::Left => {p_sprite.flip_x = true;},
}
// gotta query for sprite to control how the player "appears" to look in either direction // gotta query for sprite to control how the player "appears" to look in either direction
velocity.linvel.x = (right - left) * 200.; velocity.linvel.x = (right - left) * 200.;