Error when killing enemies
Posted: Thu Apr 17, 2014 9:53 pm
In my game the player can throw wrenches at the enemies.
But I got a problem: When I have multiple wrenches at the screen, most of the time the wrench don't kill the enemy. And I usually got an error in this.
In scripts/player.lua I got these variables:
They are the wrench X, Y and its rotation.
In scripts/enemies/spycrab.lua I got:
It's the same thing as the wrench positions.
In spycrab_update(dt) is the code that checks if an wrench collides with the player:
I've already tryied put 'break' instead of 'return #sc.X, #wr.positionsX', but when I have multiple wrenches at the screen, the program breaks the loop.
Can someone throw me a light?
But I got a problem: When I have multiple wrenches at the screen, most of the time the wrench don't kill the enemy. And I usually got an error in this.
In scripts/player.lua I got these variables:
Code: Select all
wr = {}
wr.positionsX = {}
wr.positionsY = {}
wr.rotations = {}
In scripts/enemies/spycrab.lua I got:
Code: Select all
sc = {}
sc.X = {}
sc.Y = {}
sc.Rot = {}
In spycrab_update(dt) is the code that checks if an wrench collides with the player:
Code: Select all
if #sc.X ~= 0 and #wr.positionsX ~= 0 then
for n = 1, #sc.X do
if n > #wr.positionsX then break else
if wr.positionsX[n]+wrench:getWidth() > sc.X[n] and wr.positionsX[n] < sc.X[n]+spycrab:getWidth() and wr.positionsY[n]+(wrench:getHeight()/2) > sc.Y[n] and wr.positionsY[n]+(wrench:getHeight()/2) < sc.Y[n]+spycrab:getHeight() then
table.remove(wr.positionsX, n)
table.remove(wr.positionsY, n)
table.remove(wr.rotations, n)
nadd = nadd - 1
table.remove(sc.X, n)
table.remove(sc.Y, n)
table.remove(sc.Rot, n)
scAdd = scAdd - 1
return #sc.X, #wr.positionsX
end
end
end
end
Can someone throw me a light?