The if statement in question:
Code: Select all
elseif rX[i] < rX[n] + 2 and rX[n] < rX[i] + 2 and rY[i] < rY[n] + 2 and rY[n] < rY[i] + 2 then
Code: Select all
for i = 1, #rX do
for n = 1, #rX do
if isCollided(i, n) then
Code: Select all
function doFights()
for i = 1, #rX do
for n = 1, #rX do
if isCollided(i, n) then
if rS[i] > rS[n] then
table.remove(rX, n)
table.remove(rY, n)
table.remove(rS, n)
elseif rS[i] < rS[n] then
table.remove(rX, i)
table.remove(rY, i)
table.remove(rS, i)
elseif rS[i] == rS[n] then
if love.math.random(0, 1) == 0 then
table.remove(rX, n)
table.remove(rY, n)
table.remove(rS, n)
else
table.remove(rX, i)
table.remove(rY, i)
table.remove(rS, i)
end
end
end
end
end
end
function isCollided(i, n)
if rX[i] < rX[n] + 2 and rX[n] < rX[i] + 2 and rY[i] < rY[n] + 2 and rY[n] < rY[i] + 2 then
return 1
else
return 0
end
end