diff --git a/snake-game/src/startup.rs b/snake-game/src/startup.rs index 5177b1b..80ff026 100644 --- a/snake-game/src/startup.rs +++ b/snake-game/src/startup.rs @@ -96,22 +96,32 @@ fn spawn_snake(commands: &mut Commands) { commands .entity(tail) - // .observe( |event: On, mut query: Query<(&mut Direction, &Transform)>, snake_path: Res| { - trace!("first observer working"); if let Ok((mut direction, transform)) = query.get_mut(event.0) { if let Some(new_direction) = snake_path.pick(transform) { + trace!("change direction for {:?} to {:?}", event.0, new_direction); *direction = new_direction; } } }, ) - .observe(|event: On| { - trace!("second observer working"); - }); + .observe( + |event: On, + query: Query<(Entity, &Transform), With>, + mut snake_path: ResMut| { + if let Ok((entity, transform)) = query.get(event.0) { + if let Some(removed) = snake_path.pop(transform) { + trace!( + "removed direction {:?} from snake_path by End entity {:?}", + removed, entity + ); + } + } + }, + ); } /// Создать координатную сетку