Проектная работа - WIP
This commit is contained in:
@@ -11,6 +11,7 @@ pub fn head_rotation(
|
||||
query: Single<(&mut Transform, &Direction), With<Head>>,
|
||||
mut snake_path: ResMut<SnakePath>,
|
||||
) {
|
||||
let _span = trace_span!("head_rotation").entered();
|
||||
if input.just_pressed(KeyCode::ArrowLeft) {
|
||||
let (mut transform, direction) = query.into_inner();
|
||||
let translation = transform.translation.clone();
|
||||
@@ -19,15 +20,15 @@ pub fn head_rotation(
|
||||
let mut new_direction = direction.clone();
|
||||
new_direction.rotate_left();
|
||||
if !snake_path.push(dst_pos, new_direction) {
|
||||
trace!("head_rotation - try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
dst_pos.shift(&direction);
|
||||
if !snake_path.push(dst_pos, new_direction) {
|
||||
trace!("head_rotation - try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
return;
|
||||
}
|
||||
}
|
||||
transform.rotation = new_direction.orientation();
|
||||
trace!("head_rotation - running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}");
|
||||
trace!("running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}");
|
||||
} else if input.just_pressed(KeyCode::ArrowRight) {
|
||||
let (mut transform, direction) = query.into_inner();
|
||||
let translation = transform.translation.clone();
|
||||
@@ -36,15 +37,15 @@ pub fn head_rotation(
|
||||
let mut new_direction = direction.clone();
|
||||
new_direction.rotate_right();
|
||||
if !snake_path.push(dst_pos, new_direction) {
|
||||
trace!("head_rotation - try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
dst_pos.shift(&direction);
|
||||
if !snake_path.push(dst_pos, new_direction) {
|
||||
trace!("head_rotation - try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath");
|
||||
return;
|
||||
}
|
||||
}
|
||||
transform.rotation = new_direction.orientation();
|
||||
trace!("head_rotation - running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}");
|
||||
trace!("running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +56,7 @@ pub fn snake_moving(
|
||||
query: Query<(&mut Transform, &mut Direction, &Velocity, Entity, Has<End>), Or<(With<Head>, With<Tail>, With<End>)>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let _span = trace_span!("snake_moving").entered();
|
||||
for (mut transform, mut direction, Velocity(velocity), entity, has_end) in query.into_iter() {
|
||||
// первая часть движения - до границы сетки
|
||||
let delta = velocity * time.delta_secs();
|
||||
@@ -70,7 +72,7 @@ pub fn snake_moving(
|
||||
let delta = second.1.abs();
|
||||
let pos = Position::from(&*transform);
|
||||
if let Some(dir) = snake_path.peek(&pos) {
|
||||
trace!("snake_moving - set new direction for {entity} in {pos} --> {dir}");
|
||||
trace!("set new direction for {entity} in {pos} --> {dir}");
|
||||
*direction = dir.clone();
|
||||
}
|
||||
let src = direction.get_coord(&*transform);
|
||||
|
||||
Reference in New Issue
Block a user