Проектная работа - WIP
This commit is contained in:
@@ -15,7 +15,7 @@ impl Position {
|
|||||||
Self { x, y }
|
Self { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change(&mut self, direction: &Direction) {
|
pub fn shift(&mut self, direction: &Direction) {
|
||||||
match direction {
|
match direction {
|
||||||
Direction::Up => self.y += 1,
|
Direction::Up => self.y += 1,
|
||||||
Direction::Left => self.x -= 1,
|
Direction::Left => self.x -= 1,
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ pub fn head_rotation(
|
|||||||
new_direction.rotate_left();
|
new_direction.rotate_left();
|
||||||
if !snake_path.push(dst_pos, new_direction) {
|
if !snake_path.push(dst_pos, new_direction) {
|
||||||
trace!("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.change(&direction);
|
dst_pos.shift(&direction);
|
||||||
if !snake_path.push(dst_pos, new_direction) {
|
if !snake_path.push(dst_pos, new_direction) {
|
||||||
trace!("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();
|
transform.rotation = new_direction.orientation();
|
||||||
@@ -36,9 +37,10 @@ pub fn head_rotation(
|
|||||||
new_direction.rotate_right();
|
new_direction.rotate_right();
|
||||||
if !snake_path.push(dst_pos, new_direction) {
|
if !snake_path.push(dst_pos, new_direction) {
|
||||||
trace!("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.change(&direction);
|
dst_pos.shift(&direction);
|
||||||
if !snake_path.push(dst_pos, new_direction) {
|
if !snake_path.push(dst_pos, new_direction) {
|
||||||
trace!("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();
|
transform.rotation = new_direction.orientation();
|
||||||
|
|||||||
Reference in New Issue
Block a user