示例#1
0
    void CreateNode(int direction, Obstacle obstacle2spawn, ObstacleNode _father, Vector3 pos)
    {
        for (int i = (int)(pos.x - (obstacle2spawn.size[0] / 2)); i < pos.x + (obstacle2spawn.size[0] / 2); i++)
        {
            for (int j = (int)(pos.z - (obstacle2spawn.size[1] / 2)); j < pos.z + (obstacle2spawn.size[1] / 2); j++)
            {
                if (i > 0 && i < GridLength && j > 0 && j < GridLength)
                {
                    mapGrid[i][j] = 1;
                }
            }
        }

        /*
         * for (int i = (int)pos.x; i < (int)pos.x+obstacle2spawn.size[0]; i++)
         * {
         *  for (int j = (int)pos.y; j < (int)pos.y + obstacle2spawn.size[1]; j++)
         *  {
         *
         *  }
         * }*/

        ObstacleNode aux = new ObstacleNode(_father, obstacle2spawn, direction, pos);

        if (_father != null)
        {
            obstacleList[obstacleList.IndexOf(_father)].children.Add(aux);
            obstacleList[obstacleList.IndexOf(_father)].read = true;
        }


        obstacleList.Add(aux);
    }
示例#2
0
    void Try2GrowNode(int direction, ObstacleNode _father)
    {
        float x = _father.position.x;
        float y = _father.position.z;

        Obstacle aux = obstaclePrefabList[Random.Range(0, obstaclePrefabList.Count)];


        //getting the coordinates of the new obstacle
        switch (direction)
        {
        // growing to the north
        case 0:
            y += (_father.res.size[1] / 2) + spawnLength + (aux.size[1] / 2);
            break;

        // growing to the west
        case 1:
            x += -(_father.res.size[0] / 2) - spawnLength - (aux.size[0] / 2);
            break;

        // growing to the east
        case 2:
            x += (_father.res.size[0] / 2) + spawnLength + (aux.size[0] / 2);
            break;

        //growing to the south
        case 3:
            y += -(_father.res.size[1] / 2) - spawnLength - (aux.size[1] / 2);
            break;

        //origin room
        default:
            x = 0f;
            y = 0f;
            break;
        }

        bool canBuild = false;
        bool overlaps = true;

        for (int i = (int)(x - (aux.size[0] / 2)); i < x + (aux.size[0] / 2); i++)
        {
            for (int j = (int)(y - (aux.size[1] / 2)); j < y + (aux.size[1] / 2); j++)
            {
                if (i > 0 && i < GridLength && j > 0 && j < GridLength && overlaps)
                {
                    canBuild = true;
                    overlaps = mapGrid[i][j] == 0;
                }
            }
        }

        if (canBuild && overlaps)
        {
            CreateNode(direction, aux, _father, new Vector3(x, 0, y));
        }
    }
示例#3
0
 public ObstacleNode(ObstacleNode _father, Obstacle _res, int _direction, Vector3 _position)
 {
     read      = false;
     father    = _father;
     res       = _res;
     direction = _direction;
     position  = _position;
     children  = new List <ObstacleNode>();
 }