/// <summary> /// Helper method - checks for overlap between split cubes and cancels the directional movement that causes overlap /// </summary> public void CorrectOverlap(Cube moving, Cube teammate) { if (moving.Overlaps(teammate)) { double relativeX = moving.loc_x - teammate.loc_x; double relativeY = moving.loc_y - teammate.loc_y; double relative = Math.Abs(relativeX) - Math.Abs(relativeY); // Set moving cube's coordinates so slightly-overlapped cube edges touch instead if (relative < 0) { moving.loc_y = (relativeY > 0) ? teammate.bottom + moving.width / 2 : teammate.top - moving.width / 2; } else if (relative > 0) { moving.loc_x = (relativeX > 0) ? teammate.right + moving.width / 2 : teammate.left - moving.width / 2; } else { moving.loc_x = (relativeX > 0) ? teammate.right + moving.width / 2 : teammate.left - moving.width / 2; moving.loc_y = (relativeY > 0) ? teammate.bottom + moving.width / 2 : teammate.top - moving.width / 2; } } }