So, I am trying to write some code where there will be multiple shapes.  The user can drag a shape and place it in a grid and then the user can "connect" another shape to the one just placed in the grid.  I am having a hard time figuring out how I can tell when a shape is next to another in the grid.  I was wondering if anyone could give me some ideas or hints to help me out.   
 [-O< 
Here is some code I have came up with so far:
 
	local startFlow = false
	local moveFlow = false	
	local shapeX = self:getX()--x coordinate of the shape
	local shapeY = self:getY()--y coordinate of the shape
	local flow = 0
 
	--the starting shape which starts the flow
	if shapeX == 80 and shapeY == 40 then
		local startFlow = true
		local moveFlow = true
		print("flow has began")
		flow = flow + 1
		local controlShapeX = shapeX
		local controlShapeY = shapeY
 
	end | 
I know that piece of code is very ugly haha!
Okay, in this piece of code I am trying to make see if a shape is next to another shape.  In the if statement I am trying to tell if the first shape is "connected" to the starting point which means the flow (of water) begins and the flow moves 1 shape.  I am trying to make the last shape the control shape to see if the next shape is next to the last shape.  So, I am trying to make the first shape my control shape.  Then, once the next shape is connected to the first shape; the second shape becomes the control shape to see if the next shape is next to it.  So, how can I make the last shape the control shape?  Also, how should I compare the two shapes x and y coordinates to tell if they are next to each other in the grid?
If there is another way to tell if  multiple shapes are next to each other please tell me!
So, if you have any hint, tips, or ideas I could try out I would be very thankful!!  

   ^:)^                 
 
                I am a programming noobie, so thanks in advance for helping me out and answering my questions!
Comments
Sorry if this sounds confusing (it's late here) - try sketching it on a bit of paper and you should get an idea of how it works or ask again if you get struck.
Likes: QuasarCreator
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill