I am programming games and now I want to destroy enemies. In main.lua I had a table named listOfFrog. I added the enemy by table.insert (listOfFrog, Frog (500, 400)) ... In player.lua, when the player collided with an enemy I called: enemy: boom () (with the enemy being object created from Frog class). The code in main.lua and player.lua is okay already. And the problem starts here: In Frog.lua I have a function as follows:
Code: Select all
function Frog:boom()
self.collider:destroy()
table.remove(listOfFrog, ???)
end
More, In player.lua, I handled the collision as follows:
Code: Select all
if self.collider:enter('Frog') then
local collision_data = self.collider:getEnterCollisionData('Frog')
local enemy = collision_data.collider:getObject()
if enemy.collider:getY() > self.collider:getY() then
self.collider:applyLinearImpulse(0, -100)
print("ouch")
enemy:boom()
end
end
Hope you will help me as soon as possible. Thank you so much!