Beispiel #1
0
    public override ArrayList nextNodesFrom(AStarNode node, ArrayList closedList)
    {
        ArrayList            arr   = new ArrayList();
        AStarEnemyParameters param = (AStarEnemyParameters)node.parameters;

        for (int n = -1; n <= 1; n++)
        {
            for (int m = -1; m <= 1; m++)
            {
                int x = param.x + n;
                int y = param.y + m;
                if ((n == 0 && m == 0) || (n != 0 && m != 0) || x < 0 || y < 0 || x >= mapGenerator.actualWidth || y >= mapGenerator.actualHeight)
                {
                    continue;
                }
                AStarEnemyParameters param1 = new AStarEnemyParameters(x, y, mapGenerator.tiles[x, y]);
                if (closedList != null && closedList.Contains(param1))
                {
                    continue;
                }
                float          heur  = heuristicForParameters(param1);
                AStarEnemyNode node1 = new AStarEnemyNode(param1, heur);
                if (!nodeCanBeReachedFrom(node1, node))
                {
                    continue;
                }
                arr.Add(node1);
            }
        }
        return(arr);
    }
Beispiel #2
0
    public void setStartNode()
    {
        AStarEnemyParameters parameters = new AStarEnemyParameters((int)unit.position.x, (int)-unit.position.y, mapGenerator.tiles[(int)unit.position.x, (int)-unit.position.y]);
        float heuristic = heuristicForParameters(parameters);

        startNode = new AStarEnemyNode(parameters, heuristic);
        startNode.setDistance(heuristic);
    }