From d4420701941224d1c944d134ad10f711fed688ed Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 6 Apr 2020 23:56:59 +0200 Subject: [PATCH] wip --- src/engine.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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 }; }