This is a tricky thing I think, I already thought about possible solutions but they are not elegant and more than everything I would like the opinion of the community.
Think bejeweled popcap.com/games/bejeweled2/online you click on a gem, then on another adjacent one and they swap,there may be two adjacent ones, three, four or none.
(X gem , O empty)
X X O X
X O O O
O X X O
What I would like is for the user to able to click on only one "gem" and the system will need to select the nearest one on an horizontal line (not vertical) and swap these two on the x axis.
I thought about storing the x position of the object inside an instance variable, then trying to move it on the axis checking for collision, it those happens swap the x of the two objects.
How would you do this?
Thank you very much