mirror of
https://github.com/libretro/lutro-platformer.git
synced 2025-02-21 09:43:53 +00:00
Refactoring
This commit is contained in:
parent
06c520f47f
commit
e342588abc
@ -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
|
||||
|
6
coin.lua
6
coin.lua
@ -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
|
||||
|
8
main.lua
8
main.lua
@ -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
|
||||
|
12
obake.lua
12
obake.lua
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user