Posted 14 October 2012 - 09:43 AM
function CheckCollision(x1, y1, w1, h1, x2, y2, w2, h2)
if (x1 >= x2) and (x1 <= (x2 + w2 - 1)) and (y1 >= y2) and (y1 <= (y2 + h2 - 1)) then
return true
end
return false
end
testObj = { x = 22, y = 3, w = 3, h = 1 }
function clear()
term.clear()
term.setCursorPos(1,1)
end
function draw()
clear()
term.setCursorPos(testObj.x, testObj.y)
for i = 1, testObj.w do
for i = 1, testObj.h do
write("#")
end
end
end
draw()
while true do
e, x, y = os.pullEvent("click")
if e then
print("X: ", x, " Y: ", y)
if CheckCollision(x, y, 1, 1, testObj.x, testObj.y, testObj.w, testObj.h) then -- MouseX, MouseY, 1,1
term.setCursorPos(1,1)
print("True")
sleep(.3)
draw()
end
end
end
As you can see, it detects the mouse click within the area.