Page 2 of 2

Re: first problem

Posted: Mon Dec 15, 2008 1:59 pm
by 1stAnd10
Someone else posted this code originally on the forum so full credit needs to be given to them. Sorry if any typos, doing this from memory.

function mousepressed(x, y, button)
-- left mouse button clicked
if love.mouse_left then
-- check if click was on a body on screen
if intersects(x, y, body:getX(), body:getY(), 32) -- assuming 32 is the radius of the circle body you're checking against
-- do something
end
end
end

function intersects(x1, y1, x2, y2, r)
local dx = x1 - x2
local dy = y1 - y2
return (dx*dx+dy*dy) < (r*r)
end