Beispiel #1
0
        protected virtual void CheckAndResolveBoxCollision(EntityBox <EntityType> BoxA, EntityBox <EntityType> BoxB)
        {
            Rect BoxABounds       = BoxA.GetBoxBounds();
            Rect BiggerBoxABounds = new Rect(BoxABounds.x - MinimumSafeDistance, BoxABounds.y - MinimumSafeDistance,
                                             BoxABounds.width + (2 * MinimumSafeDistance), BoxABounds.height + (2 * MinimumSafeDistance));
            Rect BoxBBounds       = BoxB.GetBoxBounds();
            Rect BiggerBoxBBounds = new Rect(BoxBBounds.x - MinimumSafeDistance, BoxBBounds.y - MinimumSafeDistance,
                                             BoxBBounds.width + (2 * MinimumSafeDistance), BoxBBounds.height + (2 * MinimumSafeDistance));

            if (VisualScriptingDrawing.RectOverlapsRect(BiggerBoxABounds, BiggerBoxBBounds))
            {
                Rect CurrentRelativeRect = BiggerBoxABounds;
                bool bNewSpotFound       = false;
                Rect NewBoxBBounds       = BiggerBoxBBounds;

                while (!bNewSpotFound)
                {
                    bool bFoundConflict = false;
                    NewBoxBBounds = new Rect(CurrentRelativeRect.x + CurrentRelativeRect.width + 1,
                                             CurrentRelativeRect.y,
                                             BiggerBoxBBounds.width,
                                             BiggerBoxBBounds.height);

                    for (int CurrentBox = 0; CurrentBox < Boxes.Count; ++CurrentBox)
                    {
                        if (Boxes[CurrentBox] != BoxB)
                        {
                            if (VisualScriptingDrawing.RectOverlapsRect(NewBoxBBounds, Boxes[CurrentBox].GetBoxBounds()))
                            {
                                bFoundConflict = true;

                                Rect NewBoxBounds = Boxes[CurrentBox].GetBoxBounds();
                                CurrentRelativeRect = new Rect(NewBoxBounds.x - MinimumSafeDistance, NewBoxBounds.y - MinimumSafeDistance,
                                                               NewBoxBounds.width + (2 * MinimumSafeDistance), NewBoxBounds.height + (2 * MinimumSafeDistance));
                            }
                        }
                    }

                    if (!bFoundConflict)
                    {
                        bNewSpotFound = true;
                    }
                }

                BoxB.MoveBoxTo(new Vector2(NewBoxBBounds.x + MinimumSafeDistance, NewBoxBBounds.y + MinimumSafeDistance));
            }
        }
Beispiel #2
0
 public virtual bool IsInsideDragArea(Rect DragArea)
 {
     return(VisualScriptingDrawing.RectOverlapsRect(DragArea, new Rect(Position.x, Position.y, Size.x, Size.y)));
 }