Exemple #1
0
        public static void MergeAnchors(FootholdAnchor a, FootholdAnchor b)
        {
            foreach (FootholdLine line in b.connectedLines)
            {
                if (line.FirstDot == b)
                {
                    line.FirstDot = a;
                }
                else if (line.SecondDot == b)
                {
                    line.SecondDot = a;
                }
                else
                {
                    throw new Exception("No anchor matches foothold");
                }

                a.connectedLines.Add(line);
            }
            b.connectedLines.Clear();
        }
Exemple #2
0
 public virtual void DoSnap()
 {
     if (InputHandler.IsKeyPushedDown(System.Windows.Forms.Keys.ShiftKey) && connectedLines.Count != 0 && connectedLines[0] is FootholdLine && board.SelectedItems.Count == 1 && board.SelectedItems[0].Equals(this))
     {
         FootholdAnchor closestAnchor = null;
         double         closestAngle  = double.MaxValue;
         bool           xClosest      = true;
         foreach (FootholdLine line in connectedLines)
         {
             FootholdAnchor otherAnchor = (FootholdAnchor)(line.FirstDot == this ? line.SecondDot : line.FirstDot);
             double         xAngle      = Math.Abs(Math.Atan((double)(Y - otherAnchor.Y) / (double)(X - otherAnchor.X)));
             double         yAngle      = Math.Abs(Math.Atan((double)(X - otherAnchor.X) / (double)(Y - otherAnchor.Y)));
             double         minAngle;
             bool           xSmaller = false;
             if (xAngle < yAngle)
             {
                 xSmaller = true; minAngle = xAngle;
             }
             else
             {
                 xSmaller = false; minAngle = yAngle;
             }
             if (minAngle < closestAngle)
             {
                 xClosest = xSmaller; closestAnchor = otherAnchor; closestAngle = minAngle;
             }
         }
         if (closestAnchor != null)
         {
             if (xClosest)
             {
                 SnapMoveAllMouseBoundItems(new XNA.Point(Parent.X + Parent.BoundItems[this].X, closestAnchor.Y));
             }
             else
             {
                 SnapMoveAllMouseBoundItems(new XNA.Point(closestAnchor.X, Parent.Y + Parent.BoundItems[this].Y));
             }
         }
     }
 }
Exemple #3
0
 public FootholdAnchor GetOtherAnchor(FootholdAnchor first)
 {
     if (FirstDot == first)
         return (FootholdAnchor)SecondDot;
     else if (SecondDot == first)
         return (FootholdAnchor)FirstDot;
     else
         throw new Exception("GetOtherAnchor: line is not properly connected");
 }
Exemple #4
0
 public void ParseOffsets(ObjectInstance instance, Board board, int x, int y)
 {
     bool ladder = l0 == "ladder";
     if (footholdOffsets != null)
     {
         foreach (List<XNA.Point> anchorList in footholdOffsets)
         {
             List<FootholdAnchor> anchors = new List<FootholdAnchor>();
             foreach (XNA.Point foothold in anchorList)
             {
                 FootholdAnchor anchor = new FootholdAnchor(board, x + foothold.X, y + foothold.Y, instance.LayerNumber, instance.PlatformNumber, true);
                 board.BoardItems.FHAnchors.Add(anchor);
                 instance.BindItem(anchor, foothold);
                 anchors.Add(anchor);
             }
             CreateFootholdsFromAnchorList(board, anchors);
         }
     }
     if (chairOffsets != null)
     {
         foreach (XNA.Point chairPos in chairOffsets)
         {
             Chair chair = new Chair(board, x + chairPos.X, y + chairPos.Y);
             board.BoardItems.Chairs.Add(chair);
             instance.BindItem(chair, chairPos);
         }
     }
 }
Exemple #5
0
 public void CreateFhAnchor()
 {
     lock (Board.ParentControl)
     {
         FootholdAnchor fhAnchor = new FootholdAnchor(Board, X, Y, Board.SelectedLayerIndex, Board.SelectedPlatform, true);
         Board.BoardItems.FHAnchors.Add(fhAnchor);
         Board.UndoRedoMan.AddUndoBatch(new List<UndoRedoAction> { UndoRedoManager.ItemAdded(fhAnchor) });
         if (connectedLines.Count == 0)
         {
             Board.BoardItems.FootholdLines.Add(new FootholdLine(Board, fhAnchor));
         }
         else
         {
             connectedLines[0].ConnectSecondDot(fhAnchor);
             Board.BoardItems.FootholdLines.Add(new FootholdLine(Board, fhAnchor));
         }
     }
 }
Exemple #6
0
        public static void MergeAnchors(FootholdAnchor a, FootholdAnchor b)
        {
            foreach (FootholdLine line in b.connectedLines)
            {
                if (line.FirstDot == b)
                    line.FirstDot = a;
                else if (line.SecondDot == b)
                    line.SecondDot = a;
                else
                    throw new Exception("No anchor matches foothold");

                a.connectedLines.Add(line);
            }
            b.connectedLines.Clear();
        }
Exemple #7
0
 public static int FHAnchorSorter(FootholdAnchor c, FootholdAnchor d)
 {
     if (c.X > d.X)
         return 1;
     else if (c.X < d.X)
         return -1;
     else
     {
         if (c.Y > d.Y)
             return 1;
         else if (c.Y < d.Y)
             return -1;
         else
         {
             if (c.LayerNumber > d.LayerNumber)
                 return 1;
             else if (c.LayerNumber < d.LayerNumber)
                 return -1;
             else
             {
                 if (c.PlatformNumber > d.PlatformNumber)
                     return 1;
                 else if (c.PlatformNumber < d.PlatformNumber)
                     return -1;
                 else
                 {
                     if (c.Parent != null && c.Parent is TileInstance && ((TileInfo)c.Parent.BaseInfo).u == "edU")
                         return -1;
                     else if (d.Parent != null && d.Parent is TileInstance && ((TileInfo)d.Parent.BaseInfo).u == "edU")
                         return 1;
                     else
                         return 0;
                 }
             }
         }
     }
 }
Exemple #8
0
 public void ParseOffsets(TileInstance instance, Board board, int x, int y)
 {
     List<FootholdAnchor> anchors = new List<FootholdAnchor>();
     foreach (XNA.Point foothold in footholdOffsets)
     {
         FootholdAnchor anchor = new FootholdAnchor(board, x + foothold.X, y + foothold.Y, instance.LayerNumber, instance.PlatformNumber, true);
         anchors.Add(anchor);
         board.BoardItems.FHAnchors.Add(anchor);
         instance.BindItem(anchor, foothold);
     }
     for (int i = 0; i < anchors.Count - 1; i++)
     {
         FootholdLine fh = new FootholdLine(board, anchors[i], anchors[i + 1]);
         board.BoardItems.FootholdLines.Add(fh);
     }
 }