When I try to fire it comes up with an error: When i add this code the error occurs. I am using bounding box.lua
Code: Select all
function update
for i, enemy in ipairs(enemies) do
for j, bullet in ipairs(bullets) do
if CheckCollision(enemy.x, enemy.y, enemy.img:getWidth(), enemy.img:getHeight(), bullet.x, bullet.y, bullet.width, bullet.height) then
table.remove(bullets, j)
table.remove(enemies, i)
kills = kills + 1
end
end
end
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
Thanks