Player controller system
(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut ship_query: Query<(&mut Transform, &Actor), With<Player>>,
)
| 55 | |
| 56 | // Player controller system |
| 57 | fn player_controller( |
| 58 | keyboard_input: Res<ButtonInput<KeyCode>>, |
| 59 | mut ship_query: Query<(&mut Transform, &Actor), With<Player>>, |
| 60 | ) { |
| 61 | for (mut ship_transform, ship) in &mut ship_query { |
| 62 | let mut direction_x: f32 = 0.0; |
| 63 | let mut direction_y = 0.0; |
| 64 | |
| 65 | if keyboard_input.pressed(KeyCode::ArrowDown) { |
| 66 | direction_y -= ship.speed.y; |
| 67 | } |
| 68 | |
| 69 | if keyboard_input.pressed(KeyCode::ArrowUp) { |
| 70 | direction_y += ship.speed.y; |
| 71 | } |
| 72 | |
| 73 | if keyboard_input.pressed(KeyCode::ArrowLeft) { |
| 74 | direction_x -= ship.speed.x; |
| 75 | } |
| 76 | |
| 77 | if keyboard_input.pressed(KeyCode::ArrowRight) { |
| 78 | direction_x += ship.speed.x; |
| 79 | } |
| 80 | |
| 81 | // Calculate the new position based on player input |
| 82 | ship_transform.translation.y = ship_transform.translation.y + direction_y; |
| 83 | ship_transform.translation.x = ship_transform.translation.x + direction_x; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | pub fn reflect_from_wall( |
| 88 | mut ship_query: Query<(&mut Transform, &Collider, &Actor), With<Player>>, |
nothing calls this directly
no outgoing calls
no test coverage detected