From 3c559635e9afacdc2d21e09802c267a5cb1f53f2 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Wed, 10 Dec 2014 21:31:17 -0500 Subject: [PATCH] better screen range checking --- lib/body.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/body.lua b/lib/body.lua index 180ef2c..85ffb02 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -507,12 +507,15 @@ function body:isInLightRange(light) end function body:isInRange(l, t, w, h, s) - local bx, by, bw, bh + local radius if self.type == 'circle' then - bx, by, bw, bh = self.x - self.radius, self.y - self.radius, self.radius * 2, self.radius * 2 + radius = self.radius else - bx, by, bw, bh = self.x, self.y, self.width, self.height + radius = (self.width > self.height and self.width or self.height) end + + local bx, by, bw, bh = self.x - radius, self.y - radius, radius * 2, radius * 2 + return self.visible and (bx+bw) > (-l/s) and bx < (-l+w)/s and (by+bh) > (-t/s) and by < (-t+h)/s end