From 3d4819cda417511fa50124fb64fee362ae2eaac9 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Mon, 3 Nov 2014 17:54:15 -0500 Subject: [PATCH] added remove method to light world to facilitate removal of items --- examples/short.lua | 6 ++++++ lib/init.lua | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/examples/short.lua b/examples/short.lua index 3350c90..342fcdf 100644 --- a/examples/short.lua +++ b/examples/short.lua @@ -77,6 +77,12 @@ function love.keypressed(k) if colorAberration == 0.0 then colorAberration = 3.0 end + elseif k == "f" then + lightWorld:remove(lightMouse) + elseif k == "g" then + lightWorld:remove(circleTest) + elseif k == "h" then + lightWorld:remove(rectangleTest) end end diff --git a/lib/init.lua b/lib/init.lua index 1b83f90..863e50c 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -417,4 +417,25 @@ function light_world:getLight(n) return self.lights[n] end +function light_world:remove(to_kill) + if to_kill:is_a(Body) then + for i = 1, #self.body do + if self.body[i] == to_kill then + table.remove(self.body, i) + return true + end + end + elseif to_kill:is_a(Light) then + for i = 1, #self.lights do + if self.lights[i] == to_kill then + table.remove(self.lights, i) + return true + end + end + end + + -- failed to find it + return false +end + return light_world