Проектная работа - WIP
This commit is contained in:
@@ -117,23 +117,3 @@ pub struct Inert(pub Direction);
|
||||
/// Путь змеи
|
||||
#[derive(Resource, Default, Debug, Deref, DerefMut)]
|
||||
pub struct SnakePath(HashMap<Position, Direction>);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::domain::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn test_snake_path() {
|
||||
let mut snake_path = SnakePath(HashMap::default());
|
||||
snake_path.push(&Transform::default(), Direction::default());
|
||||
assert_eq!(snake_path.0.len(), 1);
|
||||
|
||||
assert!(snake_path.pick(&Transform::default()) == Some((Position::default(), Direction::default())));
|
||||
assert_eq!(snake_path.0.len(), 1);
|
||||
|
||||
assert!(snake_path.drop(&Transform::default()) == Some((Position::default(), Direction::default())));
|
||||
assert_eq!(snake_path.0.len(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ mod observers;
|
||||
mod startup;
|
||||
mod tools;
|
||||
|
||||
pub use gameplay::{head_rotation, moving};
|
||||
pub use gameplay::{head_rotation, snake_moving};
|
||||
pub use startup::startup;
|
||||
pub use tools::define_log_layer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use snake_game::{head_rotation, moving, startup};
|
||||
use snake_game::{head_rotation, snake_moving, startup};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@@ -20,7 +20,7 @@ fn main() {
|
||||
.add_systems(Startup, (startup,))
|
||||
// .add_systems(PostStartup, snake_game::debug::print_all_entities)
|
||||
.add_systems(Update, (head_rotation,))
|
||||
.add_systems(FixedUpdate, (moving,))
|
||||
.add_systems(FixedUpdate, (snake_moving,))
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(
|
||||
|
||||
@@ -8,10 +8,12 @@ pub fn tail_observer(event: On<GridBarier>, mut query: Query<(&mut Direction, &T
|
||||
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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,10 +25,12 @@ pub fn cleanup_snake_path(event: On<GridBarier>, mut commands: Commands, query:
|
||||
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:?}");
|
||||
}
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -35,10 +39,12 @@ pub fn cleanup_snake_path(event: On<GridBarier>, mut commands: Commands, query:
|
||||
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() {
|
||||
velocity.0 = SNAKE_VELOCITY as f32;
|
||||
commands.entity(event.observer()).despawn();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
domain::{End, GridBarier, SnakePath, Tail},
|
||||
domain::{End, SnakePath, Tail},
|
||||
observers::{cleanup_snake_path, schedule_set_velocity, tail_observer},
|
||||
};
|
||||
|
||||
@@ -20,12 +20,14 @@ fn spawn_snake(commands: &mut Commands) {
|
||||
commands.insert_resource(SnakePath::default());
|
||||
commands.spawn(Observer::new(cleanup_snake_path));
|
||||
|
||||
/*
|
||||
commands.spawn(Observer::new(|e: On<GridBarier>| {
|
||||
let entity = e.entity;
|
||||
let src = e.src_pos;
|
||||
let dst = e.dst_pos;
|
||||
trace!("...<{entity:?}> moving {src:>16} => {dst:>16}");
|
||||
}));
|
||||
*/
|
||||
|
||||
let head = commands
|
||||
.spawn((
|
||||
|
||||
Reference in New Issue
Block a user