B:BD[
6.425] → [
3.359:584]
fn snake_movement(time: Res<Time>, mut head_position: Query<(&SnakeHead, &mut Transform)>) {
for (_, mut transform) in head_position.iter_mut() {
transform.translation.y += 0.02 * time.delta().as_millis() as f32;
fn snake_movement(
time: Res<Time>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut head_position: Query<&mut Transform, With<SnakeHead>>,
) {
for mut transform in head_position.iter_mut() {
if keyboard_input.pressed(KeyCode::KeyA) {
transform.translation.x -= 0.2 * time.delta().as_millis() as f32;
}
if keyboard_input.pressed(KeyCode::KeyD) {
transform.translation.x += 0.2 * time.delta().as_millis() as f32;
}
if keyboard_input.pressed(KeyCode::KeyS) {
transform.translation.y -= 0.2 * time.delta().as_millis() as f32;
}
if keyboard_input.pressed(KeyCode::KeyW) {
transform.translation.y += 0.2 * time.delta().as_millis() as f32;
}