Exemplo n.º 1
0
        public PathfindingNodeHorizontal(int i, int j, Tile topTile, Tile bottomTile) : base(i, j)
        {
            int topLeft = 0, topRight = Tile.Size;

            if (topTile.Id != 0)
            {
                Edge topCellBottonEdge = topTile.Edges[2];
                if (topCellBottonEdge.A.Y == Tile.Size && topCellBottonEdge.B.Y == Tile.Size)
                {
                    int right = (int)topCellBottonEdge.A.X;
                    int left  = (int)topCellBottonEdge.B.X;

                    if (right - left == Tile.Size)
                    {
                        ToRemove = true;
                        return;
                    }

                    if (topLeft != left || topRight != right)
                    {
                        if (topLeft != left)
                        {
                            topRight = left;
                        }
                        else if (topRight != right)
                        {
                            topLeft = right;
                        }
                    }
                }
            }

            int bottomLeft = 0, bottomRight = Tile.Size;

            if (bottomTile.Id != 0)
            {
                Edge bottomCellTopEdge = bottomTile.Edges[0];
                if (bottomCellTopEdge.A.Y == 0 && bottomCellTopEdge.B.Y == 0)
                {
                    int right = (int)bottomCellTopEdge.B.X;
                    int left  = (int)bottomCellTopEdge.A.X;

                    if (right - left == Tile.Size)
                    {
                        ToRemove = true;
                        return;
                    }

                    if (bottomLeft != left || bottomRight != right)
                    {
                        if (bottomLeft != left)
                        {
                            bottomRight = left;
                        }
                        else if (bottomRight != right)
                        {
                            bottomLeft = right;
                        }
                    }
                }
            }

            this.Left  = System.Math.Max(topLeft, bottomLeft);
            this.Right = System.Math.Min(topRight, bottomRight);

            NavigationPosition = new Vector2(J * Tile.Size + Left + (Right - Left) / 2, I * Tile.Size);
        }
Exemplo n.º 2
0
        public PathfindingNodeVertical(int i, int j, Tile leftTile, Tile rightTile) : base(i, j)
        {
            int leftTop = 0, leftBottom = Tile.Size;

            if (leftTile.Id != 0)
            {
                Edge leftCellRightEdge = leftTile.Edges[1];
                if (leftCellRightEdge.A.X == Tile.Size && leftCellRightEdge.B.X == Tile.Size)
                {
                    int top    = (int)leftCellRightEdge.A.Y;
                    int bottom = (int)leftCellRightEdge.B.Y;

                    if (bottom - top == Tile.Size)
                    {
                        ToRemove = true;
                        return;
                    }

                    if (leftTop != top || leftBottom != bottom)
                    {
                        if (leftTop != top)
                        {
                            leftBottom = top;
                        }
                        else if (leftBottom != bottom)
                        {
                            leftTop = bottom;
                        }
                    }
                }
            }

            int rightTop = 0, rightBottom = Tile.Size;

            if (rightTile.Id != 0)
            {
                Edge rightCellLeftEdge = rightTile.Edges[3];
                if (rightCellLeftEdge.A.X == 0 && rightCellLeftEdge.B.X == 0)
                {
                    int top    = (int)rightCellLeftEdge.B.Y;
                    int bottom = (int)rightCellLeftEdge.A.Y;

                    if (bottom - top == Tile.Size)
                    {
                        ToRemove = true;
                        return;
                    }

                    if (rightTop != top || rightBottom != bottom)
                    {
                        if (rightTop != top)
                        {
                            rightBottom = top;
                        }
                        else if (rightBottom != bottom)
                        {
                            rightTop = bottom;
                        }
                    }
                }
            }

            this.Top    = System.Math.Max(leftTop, rightTop);
            this.Bottom = System.Math.Min(leftBottom, rightBottom);

            NavigationPosition = new Vector2(J * Tile.Size, I * Tile.Size + Top + (Bottom - Top) / 2);
        }