I have a problem.
This is my collision code for my bullet and enemy
Code: Select all
local remEnemy = {}
local remShot = {}
for i,v in ipairs(player.shots) do
v.x = v.x + 5
if v.x > 800 then
table.insert(remShot, i)
end
for ii,vv in ipairs(enemies) do
if CheckCollision(v.x,v.y,2,5,vv.x,vv.y,vv.width,vv.height) then
table.insert(remEnemy, ii)
table.insert(remShot, i)
end
end
end
for i,v in ipairs(remEnemy) do
table.remove(enemies, v)
end
for i,v in ipairs(remShot) do
table.remove(player.shots, v)
end
Code: Select all
local remPlayer = {}
for i,v in ipairs(player) do
for ii,vv in ipairs(enemies) do
if CheckCollision(v.x,v.y,2,5,vv.x,vv.y,vv.width,vv.height) then
table.insert(remPlayer, i)
end
end
end
for i,v in ipairs(remPlayer) do
table.remove(player, v)
end
Code: Select all
enemies = {} -- enemy mutiple spawn
for i=0,0 do
enemy = {}
enemy.width = 72
enemy.height = 102
enemy.x = math.random(0,728)
enemy.y = math.random(0,428)
table.insert(enemies, enemy)
end
Code: Select all
player = {}
player.width = 72
player.height = 102
player.x = 365
player.y = 260