From 2ccda7996959414ff56331b100841338548cdb23 Mon Sep 17 00:00:00 2001 From: Willem Thiart Date: Sun, 11 Jan 2015 17:49:41 +0900 Subject: [PATCH 1/2] fixed the shadows of polygons without 8 vertices --- lib/body.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/body.lua b/lib/body.lua index c705f71..ac69890 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -649,7 +649,7 @@ function body:drawPolyShadow(light) for i = 1, #self.data, 2 do local vertex = vector(self.data[i], self.data[i + 1]) - local nextVertex = vector(self.data[(i + 2) % 8], self.data[(i + 2) % 8 + 1]) + local nextVertex = vector(self.data[(i + 2) % #self.data], self.data[(i + 2) % #self.data + 1]) local startToEnd = nextVertex - vertex if vector(startToEnd.y, -startToEnd.x) * (vertex - lightPosition) > 0 then local point1 = (lh - (vertex * light.z))/height_diff From 28b618c1fd4d37e32ed3f2f3bd5c7019475dc140 Mon Sep 17 00:00:00 2001 From: Michael Chabot Date: Sun, 11 Jan 2015 20:01:34 -0500 Subject: [PATCH 2/2] Fixed body and light removal. This is using runtime information to determine if to_kill is a body or a light. --- lib/init.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index c9a5610..84425f9 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -298,15 +298,23 @@ function light_world:newBody(type, ...) return self.bodies[#self.bodies] end +function light_world:is_body(target) + return target.type ~= nil +end + +function light_world:is_light(target) + return target.angle ~= nil +end + function light_world:remove(to_kill) - if to_kill:is_a(Body) then + if self:is_body(to_kill) then for i = 1, #self.bodies do if self.bodies[i] == to_kill then table.remove(self.bodies, i) return true end end - elseif to_kill:is_a(Light) then + elseif self:is_light(to_kill) then for i = 1, #self.lights do if self.lights[i] == to_kill then table.remove(self.lights, i)