Проектная работа - WIP

This commit is contained in:
3 changed files with 124 additions and 103 deletions
+22 -3
View File
@@ -37,7 +37,7 @@ fn spawn_snake(commands: &mut Commands) {
vec2(HEAD_SIZE as f32, HEAD_SIZE as f32),
),
Transform {
translation: vec3(0.0, 0.0, 1.0),
translation: vec3(0.0, 0.0, 0.0),
..Default::default()
},
))
@@ -48,7 +48,7 @@ fn spawn_snake(commands: &mut Commands) {
vec2(HEAD_SIZE as f32 * 0.3, HEAD_SIZE as f32 * 0.3),
),
Transform {
translation: vec3(HEAD_SIZE as f32 * -0.25, HEAD_SIZE as f32 * 0.25, 0.0),
translation: vec3(HEAD_SIZE as f32 * -0.25, HEAD_SIZE as f32 * 0.25, 1.0),
..Default::default()
},
ChildOf(head),
@@ -59,7 +59,7 @@ fn spawn_snake(commands: &mut Commands) {
vec2(HEAD_SIZE as f32 * 0.2, HEAD_SIZE as f32 * 0.2),
),
Transform {
translation: vec3(HEAD_SIZE as f32 * 0.25, HEAD_SIZE as f32 * 0.25, 0.0),
translation: vec3(HEAD_SIZE as f32 * 0.25, HEAD_SIZE as f32 * 0.25, 1.0),
..Default::default()
},
ChildOf(head),
@@ -93,6 +93,25 @@ fn spawn_snake(commands: &mut Commands) {
commands.entity(event.0).remove::<ObservedBy>();
},
);
commands
.entity(tail)
//
.observe(
|event: On<GridBarier>,
mut query: Query<(&mut Direction, &Transform)>,
snake_path: Res<SnakePath>| {
trace!("first observer working");
if let Ok((mut direction, transform)) = query.get_mut(event.0) {
if let Some(new_direction) = snake_path.pick(transform) {
*direction = new_direction;
}
}
},
)
.observe(|event: On<GridBarier>| {
trace!("second observer working");
});
}
/// Создать координатную сетку