Exemple #1
0
    void Chase()
    {
        if (player == null)
        {
            player = Map.Player.transform;
            return;
        }

        int goalX  = Mathf.RoundToInt(player.position.x);
        int goalY  = Mathf.RoundToInt(player.position.y);
        int startX = Mathf.RoundToInt(transform.position.x);
        int startY = Mathf.RoundToInt(transform.position.y);

        Pathfinder.Point[] points = Pathfinder.FindPath(startX, startY, goalX, goalY);

        if (points == null)
        {
            return;
        }

        if (points.Length < 1)
        {
            return;
        }

        Pathfinder.Point point = points[0];

        if (point == null)
        {
            return;
        }

        Move(point.X - startX, point.Y - startY);
    }
Exemple #2
0
    //public Pathfinder.Point[] GetVisibleLine (int x0, int y0)

    public static bool PlotLine(int x, int y)
    {
        Pathfinder.Point point = new Pathfinder.Point(x, y);
        if (x > 0 && y > 0 && x < Map.Width && y < Map.Height && Map.Walls [x, y] == null)
        {
            if (!VisibleSquares.Contains(point))
            {
                VisibleSquares.Add(new Pathfinder.Point(x, y));
            }
        }
        return(true);
    }
Exemple #3
0
    void Patrol()
    {
        if (Route == null)
        {
            return;
        }

        if (Route.Length < 1)
        {
            return;
        }

        if (Index >= Route.Length)
        {
            Index = 0;
        }

        Pathfinder.Point point = Route[Index];

        int x = Mathf.RoundToInt(transform.position.x);
        int y = Mathf.RoundToInt(transform.position.y);

        if (point.X == x && point.Y == y)
        {
            Index++;
            return;
        }

        Pathfinder.Point[] points = Pathfinder.FindPath(x, y, point.X, point.Y);

        point = points[0];

        if (point == null)
        {
            return;
        }

        Move(point.X - x, point.Y - y);
    }