Проектная работа - WIP
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use bevy::{ecs::observer::ObservedBy, prelude::*, winit::WinitSettings};
|
||||
use bevy::{prelude::*, winit::WinitSettings};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::domain::{End, Grid, GridBarier, SnakePath, Tail};
|
||||
use crate::{
|
||||
domain::{End, Grid, SnakePath, Tail},
|
||||
tools::{end_observer, schedule_set_velocity},
|
||||
};
|
||||
|
||||
/// Настройка частоты кадров
|
||||
pub fn setup_frame_rate(mut winit: ResMut<WinitSettings>) {
|
||||
@@ -37,7 +40,7 @@ fn spawn_snake(commands: &mut Commands) {
|
||||
vec2(HEAD_SIZE as f32, HEAD_SIZE as f32),
|
||||
),
|
||||
Transform {
|
||||
translation: vec3(0.0, 0.0, 0.0),
|
||||
translation: vec3(0.0, 0.0, 1.0),
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
@@ -82,46 +85,8 @@ fn spawn_snake(commands: &mut Commands) {
|
||||
},
|
||||
))
|
||||
.id();
|
||||
|
||||
commands.entity(head).observe(
|
||||
move |event: On<GridBarier>,
|
||||
mut commands: Commands,
|
||||
mut query: Query<&mut Velocity, With<Tail>>| {
|
||||
if let Ok(mut velocity) = query.get_mut(tail) {
|
||||
velocity.0 = SNAKE_VELOCITY as f32;
|
||||
}
|
||||
commands.entity(event.0).remove::<ObservedBy>();
|
||||
},
|
||||
);
|
||||
|
||||
commands
|
||||
.entity(tail)
|
||||
.observe(
|
||||
|event: On<GridBarier>,
|
||||
mut query: Query<(&mut Direction, &Transform)>,
|
||||
snake_path: Res<SnakePath>| {
|
||||
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<GridBarier>,
|
||||
query: Query<(Entity, &Transform), With<End>>,
|
||||
mut snake_path: ResMut<SnakePath>| {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
commands.entity(head).observe(schedule_set_velocity(tail));
|
||||
commands.entity(tail).observe(end_observer);
|
||||
}
|
||||
|
||||
/// Создать координатную сетку
|
||||
|
||||
Reference in New Issue
Block a user