Controlling the snake
This commit is contained in:
parent
e860af1d7a
commit
a62eb40527
20
src/main.rs
20
src/main.rs
@ -22,9 +22,23 @@ fn spawn_snake(commands: &mut Commands, materials: Res<Materials>) {
|
||||
.with(SnakeHead);
|
||||
}
|
||||
|
||||
fn snake_movement(mut head_positions: Query<(&SnakeHead, &mut Transform)>) {
|
||||
for (_head, mut transform) in head_positions.iter_mut() {
|
||||
transform.translation.y += 2.;
|
||||
fn snake_movement(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut head_positions: Query<&mut Transform, With<SnakeHead>>,
|
||||
) {
|
||||
for mut transform in head_positions.iter_mut() {
|
||||
if keyboard_input.pressed(KeyCode::Left) {
|
||||
transform.translation.x -= 2.;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Right) {
|
||||
transform.translation.x += 2.;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Down) {
|
||||
transform.translation.y -= 2.;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Up) {
|
||||
transform.translation.y += 2.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user