Exemplo n.º 1
0
    public bool IsValid()
    {
        if (Layer == null)
        {
            return(false);
        }
        if (Done == null)
        {
            return(false);
        }
        if (ID == null)
        {
            return(false);
        }

        if (!Layer.InLayerBounds(EndX, EndY))
        {
            return(false);
        }

        if (!Layer.IsSpotWalkable(StartX, StartY))
        {
            // Within a solid tile.
            return(false);
        }

        if (!Layer.IsSpotWalkable(EndX, EndY))
        {
            // Within a solid tile.
            return(false);
        }

        return(true);
    }
Exemplo n.º 2
0
    private static List <Node> GetNear(Node node, TileLayer layer)
    {
        // Want to add nodes connected to the center node, if they are walkable.
        // This code stops the pathfinder from cutting corners, and going through walls that are diagonal from each other.

        near.Clear();

        // Left
        left = false;
        if (layer.IsSpotWalkable(node.X - 1, node.Y))
        {
            near.Add(new Node()
            {
                X = node.X - 1, Y = node.Y
            });
            left = true;
        }

        // Right
        right = false;
        if (layer.IsSpotWalkable(node.X + 1, node.Y))
        {
            near.Add(new Node()
            {
                X = node.X + 1, Y = node.Y
            });
            right = true;
        }

        // Above
        above = false;
        if (layer.IsSpotWalkable(node.X, node.Y + 1))
        {
            near.Add(new Node()
            {
                X = node.X, Y = node.Y + 1
            });
            above = true;
        }

        // Below
        below = false;
        if (layer.IsSpotWalkable(node.X, node.Y - 1))
        {
            near.Add(new Node()
            {
                X = node.X, Y = node.Y - 1
            });
            below = true;
        }

        // Above-Left
        if (left && above)
        {
            if (layer.IsSpotWalkable(node.X - 1, node.Y + 1))
            {
                near.Add(new Node()
                {
                    X = node.X - 1, Y = node.Y + 1
                });
            }
        }

        // Above-Right
        if (right && above)
        {
            if (layer.IsSpotWalkable(node.X + 1, node.Y + 1))
            {
                near.Add(new Node()
                {
                    X = node.X + 1, Y = node.Y + 1
                });
            }
        }

        // Below-Left
        if (left && below)
        {
            if (layer.IsSpotWalkable(node.X - 1, node.Y - 1))
            {
                near.Add(new Node()
                {
                    X = node.X - 1, Y = node.Y - 1
                });
            }
        }

        // Below-Right
        if (right && below)
        {
            if (layer.IsSpotWalkable(node.X + 1, node.Y - 1))
            {
                near.Add(new Node()
                {
                    X = node.X + 1, Y = node.Y - 1
                });
            }
        }

        return(near);
    }