diff --git a/src/engine.rs b/src/engine.rs index a3690d4..e07355f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -118,7 +118,9 @@ fn closest_point(level: &Level, pos: &Position, angle: Radian) -> (Tile, Positio let mut tile = Tile::Empty; while tile == Tile::Empty && level.contains(next_point) { - if next_point.distance(x_candidate) < next_point.distance(y_candidate) { + println!("x_candidate: {:?}, distance: {}", x_candidate, pos.distance(x_candidate)); + println!("y_candidate: {:?}, distance: {}", y_candidate, pos.distance(y_candidate)); + if pos.distance(x_candidate) < pos.distance(y_candidate) { next_point = x_candidate; x_candidate = Position { x: x_candidate.x + x_step.signum(), @@ -131,16 +133,28 @@ fn closest_point(level: &Level, pos: &Position, angle: Radian) -> (Tile, Positio y: y_candidate.y + y_step.signum(), }; } - // println!("next candidate: {:?}", next_point); + println!("next candidate: {:?}", next_point); tile = if next_point.x.fract() == 0.0 { let mut position = next_point; position.x += 0.5 * x_step.signum(); - level.tile_at(position) + let tile = level.tile_at(position); + if tile == Tile::Wall { + position.x -= x_step.signum(); + let opposite_tile = level.tile_at(position); + assert_eq!(opposite_tile, Tile::Empty); + } + tile } else { let mut position = next_point; position.y += 0.5 * y_step.signum(); - level.tile_at(position) + let tile = level.tile_at(position); + if tile == Tile::Wall { + position.y -= y_step.signum(); + let opposite_tile = level.tile_at(position); + assert_eq!(opposite_tile, Tile::Empty); + } + tile }; }