Do it the way the red square, which is fixed, you can only move the green rectangle, and all this is done with the mouse, they can only move vertically and horizontally, that is, in such a situation in which there are, it is necessary to think ahead, and you can stall and pull the square is no longer able to .