Something like this might work:
set display mode desktop width(), desktop height(), 32
sync on : sync rate 60 : sync
autocam off
position camera 0, 50, -400
point camera 0, 50, 0
make object cube 1, 100
position object 1, -200, 50, 0
color object 1, rgb(255, 0, 0)
make object cube 2, 100
position object 2, 200, 50, 0
color object 2, rgb(0, 255, 0)
make object plane 3, 1000, 1000
color object 3, rgb(255, 0, 255)
xrotate object 3, 270
objectsGlued = 0
oldClickObject = 0
repeat
text 20, 20, "Left mouse click to select, drag and snap an object"
text 20, 40, "Right mouse click to select and move single object"
text 20, 70, "Press <space> to exit."
mouseClickNow = mouseClick()
` use mouseClick value 1 (left click) to move and snap objects
` use mouseClick value 2 (right click) to move target object alone
mouseXNow = mouseX()
mouseYNow = mouseY()
if oldClickObject = 0 then clickObject = pick object(mouseXNow, mouseYNow, 1, 2)
pickXNow# = get pick vector X()
if clickObject > 0
if mouseClickNow = 1
if objectsGlued
position object clickObject, pickXNow#, 50.0, 0.0
if object position x(clickObject)< object position x(3 - clickObject)
position object 3 - clickObject, pickXNow#+100.0, 50.0, 0.0
else
position object 3 - clickObject, pickXNow#-100.0, 50.0, 0.0
endif
else
position object clickObject, pickXNow#, 50.0, 0.0
if abs(object position x(1)-object position x(2))< 110.0 then objectsGlued = 1
endif
else
if mouseClickNow = 2
objectsGlued = 0
position object clickObject, pickXNow#, 50.0, 0.0
endif
endif
else
oldClickObject = 0
endif
sync
until spacekey()
end
It isn't quite right yet - if you right click the green cube to move it past the dark red block control then switches to the dark red as they pass. Anyone care to fix the bug?
Edit Fixed code, I hope:
set display mode desktop width(), desktop height(), 32
sync on : sync rate 60 : sync
autocam off
position camera 0, 50, -400
point camera 0, 50, 0
make object cube 1, 100
position object 1, -200, 50, 0
color object 1, rgb(255, 0, 0)
make object cube 2, 100
position object 2, 200, 50, 0
color object 2, rgb(0, 255, 0)
make object plane 3, 1000, 1000
color object 3, rgb(255, 0, 255)
xrotate object 3, 270
objectsGlued = 0
oldClickObject = 0
repeat
text 20, 20, "Left mouse click to select, drag and snap an object"
text 20, 40, "Right mouse click to select and move single object"
text 20, 70, "Press <space> to exit."
text 20, 100, "clickObject = "+str$(clickObject)
text 20, 120, "oldClickObject = "+str$(oldClickObject)
mouseClickNow = mouseClick()
clickObject = 0
` use mouseClick value 1 (left click) to move and snap objects
` use mouseClick value 2 (right click) to move target object alone
mouseXNow = mouseX()
mouseYNow = mouseY()
if mouseClickNow > 0 then clickObject = pick object(mouseXNow, mouseYNow, 1, 2)
if oldClickObject = 0
oldClickObject = clickObject
endif
pickXNow# = get pick vector X()
if clickObject > 0
if mouseClickNow = 1
if objectsGlued
position object oldClickObject, pickXNow#, 50.0, 0.0
if object position x(oldClickObject)< object position x(3 - oldClickObject)
position object 3 - oldClickObject, pickXNow#+100.0, 50.0, 0.0
else
position object 3 - oldClickObject, pickXNow#-100.0, 50.0, 0.0
endif
else
position object oldClickObject, pickXNow#, 50.0, 0.0
if abs(object position x(1)-object position x(2))< 110.0 then objectsGlued = 1
endif
else
if mouseClickNow = 2
objectsGlued = 0
position object oldClickObject, pickXNow#, 50.0, 0.0
endif
endif
else
oldClickObject = 0
endif
sync
until spacekey()
end
It looks a bit more complex than it needs to be to me.