Проектная работа - WIP
This commit is contained in:
@@ -1,50 +1,16 @@
|
||||
use crate::domain::*;
|
||||
use crate::{domain::*, tools::Position};
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[allow(unused)]
|
||||
/// Слушатель событий [GridBarier] для хвоста, обновляющий направление его движения из ресурса [SnakePath] и позволяющий следовать за головой
|
||||
pub fn tail_observer(event: On<GridBarier>, mut query: Query<(&mut Direction, &Transform)>, snake_path: Res<SnakePath>) {
|
||||
let entity = event.entity;
|
||||
if event.observer() == entity {
|
||||
if let Ok((mut direction, transform)) = query.get_mut(event.entity) {
|
||||
/*
|
||||
if let Some((position, new_direction)) = snake_path.pick(transform) {
|
||||
trace!("change direction for {entity:?} in {position:?} to {new_direction:?}");
|
||||
*direction = new_direction;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Слушатель событий [GridBarier] для конца змеи, обновляющий направление его движения из ресурса [SnakePath] и удаляющий полученные значения из [SnakePath]
|
||||
pub fn cleanup_snake_path(event: On<GridBarier>, mut commands: Commands, query: Query<&Transform, With<End>>) {
|
||||
if let Ok(transform) = query.get(event.entity) {
|
||||
// trace!("schedule cleaning SnakePath for {:?}", transform);
|
||||
let transform = transform.clone();
|
||||
commands.queue(move |world: &mut World| {
|
||||
let mut snake_path = world.resource_mut::<SnakePath>();
|
||||
/*
|
||||
if let Some((pos, dir)) = snake_path.drop(&transform) {
|
||||
let map = snake_path.debug();
|
||||
trace!("removed entry from SnakePath: {pos:?} => {dir:?}\n\tsnake_path: {map:?}");
|
||||
}
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Запланировать установку скорости движения [Velocity] при следующем событии [GridBarier]
|
||||
pub fn schedule_set_velocity(tail: Entity) -> impl Fn(On<GridBarier>, Commands, Query<(&mut Velocity, &Transform)>) {
|
||||
move |event: On<GridBarier>, mut commands: Commands, mut query: Query<(&mut Velocity, &Transform)>| {
|
||||
if let Ok((mut velocity, transform)) = query.get_mut(tail) {
|
||||
/*
|
||||
if event.dst_pos != transform.into() {
|
||||
let position = Position::from(transform);
|
||||
if event.position != position {
|
||||
velocity.0 = SNAKE_VELOCITY as f32;
|
||||
commands.entity(event.observer()).despawn();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user