Controlling the snake

This commit is contained in:
Timothy Warren 2020-12-24 13:49:23 -05:00
parent e860af1d7a
commit a62eb40527

View File

@ -22,11 +22,25 @@ fn spawn_snake(commands: &mut Commands, materials: Res<Materials>) {
.with(SnakeHead); .with(SnakeHead);
} }
fn snake_movement(mut head_positions: Query<(&SnakeHead, &mut Transform)>) { fn snake_movement(
for (_head, mut transform) in head_positions.iter_mut() { 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.; transform.translation.y += 2.;
} }
} }
}
fn main() { fn main() {
App::build() App::build()