From a7265e0994ec823a831be9b17ffb71812d00d176 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Mon, 4 Oct 2021 01:00:31 -0400 Subject: [PATCH] fix block dist detection --- game/src/scenes/ingame_scene/world.rs | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/game/src/scenes/ingame_scene/world.rs b/game/src/scenes/ingame_scene/world.rs index aa79317..9a65d06 100644 --- a/game/src/scenes/ingame_scene/world.rs +++ b/game/src/scenes/ingame_scene/world.rs @@ -45,13 +45,14 @@ impl WorldSpaceRender for InGameScreen { .appear .iter() .map(|zone| { - // Vector2::new( - // zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), - // zone.y - cur_level.platform_tex.height as f32, - // ) - // .distance_to(self.player.position) as i32 - ((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x) - .abs() as i32 + let left_edge_dist = (zone.x + WORLD_LEVEL_X_OFFSET) - self.player.position.x; + let right_edge_dist = + (zone.x + zone.width + WORLD_LEVEL_X_OFFSET) - self.player.position.x; + if left_edge_dist < 0.0 && right_edge_dist > 0.0 { + 0 + } else { + left_edge_dist.abs().min(right_edge_dist.abs()) as i32 + } }) .min() .unwrap_or(i32::MAX); @@ -88,13 +89,14 @@ impl WorldSpaceRender for InGameScreen { .disappear .iter() .map(|zone| { - // Vector2::new( - // zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), - // zone.y - cur_level.platform_tex.height as f32, - // ) - // .distance_to(self.player.position) as i32 - ((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x) - .abs() as i32 + let left_edge_dist = (zone.x + WORLD_LEVEL_X_OFFSET) - self.player.position.x; + let right_edge_dist = + (zone.x + zone.width + WORLD_LEVEL_X_OFFSET) - self.player.position.x; + if left_edge_dist < 0.0 && right_edge_dist > 0.0 { + 0 + } else { + left_edge_dist.abs().min(right_edge_dist.abs()) as i32 + } }) .min() .unwrap_or(i32::MAX);