Refactoring

This commit is contained in:
Jean-André Santoni 2017-06-27 10:50:11 +02:00
parent 06c520f47f
commit e342588abc
5 changed files with 13 additions and 25 deletions

View File

@ -25,11 +25,7 @@ end
function bigcoin:on_collide(e1, e2, dx, dy)
if e2.type == "ninja" then
lutro.audio.play(sfx_coin)
for i=1, #entities do
if entities[i] == self then
table.remove(entities, i)
end
end
entities_remove(self)
gold = gold + 10
end
end

View File

@ -22,11 +22,7 @@ end
function coin:on_collide(e1, e2, dx, dy)
if e2.type == "ninja" then
lutro.audio.play(sfx_coin)
for i=1, #entities do
if entities[i] == self then
table.remove(entities, i)
end
end
entities_remove(self)
gold = gold + 1
end
end

View File

@ -39,6 +39,14 @@ local add_entity_from_map = function(object)
end
end
function entities_remove(entity)
for i=1, #entities do
if entities[i] == entity then
table.remove(entities, i)
end
end
end
function lutro.load()
camera_x = 0
camera_y = 0

View File

@ -51,11 +51,7 @@ function obake:update(dt)
end
if self.die == 1 then
for i=1, #entities do
if entities[i] == self then
table.remove(entities, i)
end
end
entities_remove(self)
end
self.t = self.t + dt
@ -109,11 +105,7 @@ function obake:on_collide(e1, e2, dx, dy)
lutro.audio.play(sfx_enemyhit)
self.hp = self.hp - 1
for i=1, #entities do
if entities[i] == e2 then
table.remove(entities, i)
end
end
entities_remove(e2)
if self.hp <= 0 then
lutro.audio.play(sfx_enemydie)

View File

@ -72,11 +72,7 @@ function porc:update(dt)
-- table.insert(entities, newPart(
-- {x = self.x + self.width/2, y = self.y + self.height / 2}))
-- end
for i=1, #entities do
if entities[i] == self then
table.remove(entities, i)
end
end
entities_remove(self)
end