This is the code that checks for the collisions:
Code: Select all
function updateball(dt)
for i=1, #balls do
if checkcollision(balls[i].x, balls[i].y, 32, love.mouse.getX(), love.mouse.getY(), 1) then
str = "true"
else
str = "false"
end
end
end
Here's the checkcollision function:
Code: Select all
function checkcollision(x1, y1, s1, x2, y2, s2)
if x1 > (x2 + s2) or (x1 + s1) < x2 then return false end
if y1 > (y2 + s2) or (y1 + s1) < y2 then return false end
return true
end
If you wanna test it ingame you press q to add a new ball to the table.