I have some simple logic that creates a square shaped sprite when the user touches the screen, this box expands evenly on all sides while the user holds the press.
I want the expansion to halt on any side that collides with another object.
For example, in the image below...
The user presses and holds, the initial box is created and starts to expand.
The user continues to hold the box expands evenly on all 4 sides.
The user continues to hold, but the right hand side connects with another object so the expansion of the right side stops and the expansion continues on the left, top and bottom sides.
What would be the best way to implement this type of expansion?