Collision issue with 'w2'
Posted: Fri Mar 09, 2018 12:40 am
I am very new to Löve and am trying to make a basic top-down shooter game, but I am having an issue with collision.
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
What really confuses me is i am also using this code to check my player-enemy collision and it works.
Thanks
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