Miguel can now look left and right
This commit is contained in:
@@ -20,7 +20,7 @@ enum Facing {
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Default, Component)]
|
||||
#[derive(Default, Component, LdtkEntity)]
|
||||
pub(crate) struct Player {
|
||||
direction: Facing,
|
||||
}
|
||||
@@ -38,7 +38,7 @@ struct PlayerBundle {
|
||||
}
|
||||
|
||||
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>>,
|
||||
) {
|
||||
// let movement_direction =
|
||||
@@ -53,21 +53,25 @@ fn player_movement(
|
||||
// } else {
|
||||
// return;
|
||||
// };
|
||||
for (mut velocity, ground_detection, mut player, mut p_transform) in &mut query {
|
||||
// let Right = if input.pressed(KeyCode::KeyD) { 1. } else { 0. };
|
||||
// let left = if input.pressed(KeyCode::KeyA) { 1. } else { 0. };
|
||||
|
||||
for (mut velocity, ground_detection, mut player, mut p_sprite) in &mut query {
|
||||
let right = if input.pressed(KeyCode::KeyD) {
|
||||
player.direction = Facing::Right;
|
||||
1.
|
||||
} else {
|
||||
0.
|
||||
};
|
||||
let left = if input.pressed(KeyCode::KeyA) {
|
||||
player.direction = Facing::Left;
|
||||
1.
|
||||
} else {
|
||||
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
|
||||
|
||||
velocity.linvel.x = (right - left) * 200.;
|
||||
|
||||
Reference in New Issue
Block a user