diff options
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/state.rs b/src/state.rs index b87db1b..ca18f71 100644 --- a/src/state.rs +++ b/src/state.rs @@ -56,9 +56,22 @@ impl GameState { } fn update_player_collisions(&mut self) { - - // TODO: One player rear-ending another - // TODO: Ending up in the same block from different lanes + let same_lanes_before = self.players[0].position.y == self.players[1].position.y; + let same_lanes_after = self.players[0].next_position.y == self.players[1].next_position.y; + let first_passing_second = self.players[0].position.x < self.players[1].position.x + && self.players[0].next_position.x >= self.players[1].next_position.x; + let second_passing_first = self.players[1].position.x < self.players[0].position.x + && self.players[1].next_position.x >= self.players[0].next_position.x; + let same_x_after = self.players[0].next_position.x == self.players[1].next_position.x; + + if same_lanes_before && same_lanes_after && first_passing_second { + self.players[0].next_position.x = self.players[1].next_position.x - 1; + } else if same_lanes_before && same_lanes_after && second_passing_first { + self.players[1].next_position.x = self.players[0].next_position.x - 1; + } else if same_lanes_after && same_x_after { + self.players[0].bonked_while_changing_lanes(); + self.players[1].bonked_while_changing_lanes(); + } } fn update_player_travel(&mut self) { @@ -121,6 +134,11 @@ impl Player { } } + fn bonked_while_changing_lanes(&mut self) { + self.next_position.y = self.position.y; + self.next_position.x = self.position.x + self.speed - 1; + } + fn move_along( &mut self, obstacles: &[Position], |