예제 #1
0
    public void UpdateNavigationMap()
    {
        foreach (int pointID in _aStar.GetPoints())
        {
            _aStar.SetPointDisabled(pointID, false);
            _gridRects[pointID].Color = _enableColor;
        }

        Godot.Collections.Array obstacles = GetTree().GetNodesInGroup("Obstacles");

        foreach (Node2D obstacle in obstacles)
        {
            if (obstacle is TileMap)
            {
                TileMap tileMap = (TileMap)obstacle;
                foreach (Vector2 tile in tileMap.GetUsedCells())
                {
                    int tileID = getPointID((int)tile.x, (int)tile.y);
                    if (_aStar.HasPoint(tileID))
                    {
                        _aStar.SetPointDisabled(tileID, true);
                        _gridRects[tileID].Color = _disableColor;
                    }
                }
            }
            else if (obstacle is Agent)
            {
                Vector2 tile   = _tileMap.WorldToMap(obstacle.GlobalPosition);
                int     tileID = getPointID((int)tile.x, (int)tile.y);
                if (_aStar.HasPoint(tileID))
                {
                    _aStar.SetPointDisabled(tileID, true);
                    _gridRects[tileID].Color = _disableColor;
                }
            }
        }
    }