Example #1
0
    void setNeightbors(GameObject obj, int row, int col)
    {
        MapElementController mapElement = obj.GetComponent <MapElementController>();

        mapElement.posMatrix = new Vector2(row, col);
        // if (row < 39 && col > 0)
        //     mapElement.neightbors.Add(mapElements[row + 1, col - 1]);
        if (row < 39)
        {
            mapElement.neightbors.Add(mapElements[row + 1, col]);
        }
        // if (row < 39 && col < 39)
        //     mapElement.neightbors.Add(mapElements[row + 1, col + 1]);
        if (col < 39)
        {
            mapElement.neightbors.Add(mapElements[row, col + 1]);
        }
        // if (row > 0 && col < 39)
        //     mapElement.neightbors.Add(mapElements[row - 1, col + 1]);
        if (row > 0)
        {
            mapElement.neightbors.Add(mapElements[row - 1, col]);
        }
        // if (row > 0 && col > 0)
        //     mapElement.neightbors.Add(mapElements[row - 1, col - 1]);
        if (col > 0)
        {
            mapElement.neightbors.Add(mapElements[row, col - 1]);
        }
    }
Example #2
0
    int ComputeCost(GameObject target, int steps, GameObject player)
    {
        MapElementController targetNode = target.GetComponent <MapElementController>();
        MapElementController playerNode = player.GetComponent <MapElementController>();
        int distanceTargetPlayer        = (int)Mathf.Max(Mathf.Abs(targetNode.posMatrix.x - playerNode.posMatrix.x), Mathf.Abs(targetNode.posMatrix.y - playerNode.posMatrix.y));
        int cost = steps + distanceTargetPlayer + targetNode.elementCost;

        return(cost);
    }