Add basic player movement system
This commit is contained in:
parent
66854be921
commit
9e16c22eb5
@ -19,5 +19,6 @@ fn main() {
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup.system())
|
||||
.add_startup_system(add_player.system())
|
||||
.add_system(player_movement.system())
|
||||
.run();
|
||||
}
|
||||
|
@ -50,6 +50,35 @@ pub fn add_player(
|
||||
});
|
||||
}
|
||||
|
||||
pub fn player_movement(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut query: Query<(&Player, &mut Transform)>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if let Ok((_, mut transform)) = query.single_mut() {
|
||||
let mut direction = Vec2::ZERO;
|
||||
|
||||
if keyboard_input.pressed(KeyCode::A) {
|
||||
direction.x -= 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::D) {
|
||||
direction.x += 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::S) {
|
||||
direction.y -= 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::W) {
|
||||
direction.y += 1.0;
|
||||
}
|
||||
|
||||
let translation = &mut transform.translation;
|
||||
let delta_seconds = time.delta_seconds();
|
||||
|
||||
translation.x += delta_seconds * direction.x * 100.0;
|
||||
translation.y += delta_seconds * direction.y * 100.0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn greet_player(
|
||||
query: Query<&Name, With<Player>>,
|
||||
time: Res<Time>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user