17 lines
731 B
Rust
17 lines
731 B
Rust
use crate::domain::*;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
/// Запланировать установку скорости движения [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) {
|
|
let position = Position::from(transform);
|
|
if event.position != position {
|
|
velocity.0 = SNAKE_VELOCITY as f32;
|
|
commands.entity(event.observer()).despawn();
|
|
}
|
|
}
|
|
}
|
|
}
|