Controlling the snake
This commit is contained in:
parent
e860af1d7a
commit
a62eb40527
18
src/main.rs
18
src/main.rs
@ -22,10 +22,24 @@ 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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user