added remove method to light world to facilitate removal of items

This commit is contained in:
Tim Anema 2014-11-03 17:54:15 -05:00
parent e74c0d8961
commit 3d4819cda4
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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