Fixed body and light removal.

This is using runtime information to determine if to_kill is a body or a
light.
This commit is contained in:
Michael Chabot 2015-01-11 20:01:34 -05:00
parent 2c00eb0bc7
commit 28b618c1fd

View File

@ -298,15 +298,23 @@ function light_world:newBody(type, ...)
return self.bodies[#self.bodies] return self.bodies[#self.bodies]
end 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) 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 for i = 1, #self.bodies do
if self.bodies[i] == to_kill then if self.bodies[i] == to_kill then
table.remove(self.bodies, i) table.remove(self.bodies, i)
return true return true
end end
end end
elseif to_kill:is_a(Light) then elseif self:is_light(to_kill) then
for i = 1, #self.lights do for i = 1, #self.lights do
if self.lights[i] == to_kill then if self.lights[i] == to_kill then
table.remove(self.lights, i) table.remove(self.lights, i)