示例#1
0
    void Awake()
    {
        m_strategy      = new TDTowerStrategy();
        m_configuration = new TDConfiguration();
        m_configuration.readFromResource();

        GameObject terrain       = getTerrain();
        Bounds     terrainBounds = terrain.renderer.bounds;
        Vector3    lowPnt        = from3dTo2d(terrainBounds.min);
        Vector3    highPnt       = from3dTo2d(terrainBounds.max);

        m_grid = new TDGrid();
        m_grid.initialize(m_configuration.gridNbCellsX, m_configuration.gridNbCellsY,
                          lowPnt.x, lowPnt.y, highPnt.x - lowPnt.x, highPnt.y - lowPnt.y);

        // Take into account obstacles
        GameObject [] aObstacles = getAllObstacles();
        foreach (GameObject obj in aObstacles)
        {
            TDGrid.CellState cellState = TDGrid.CellState.eBusy;
            switch (obj.tag)
            {
            case "Player":
                cellState = TDGrid.CellState.ePlayer;
                break;

            case "EnemyRespawn":
                cellState = TDGrid.CellState.eEnemyRespawn;
                break;
            }
            Bounds b = obj.renderer.bounds;
            occupyRegion(b.min, b.max, cellState);
        }

        // put the dynamic obstacles
        uint treesBuilt = 0;

        while (treesBuilt < m_configuration.nbTrees)
        {
            uint        i    = (uint)((Random.value) * (float)(m_grid.nbCellsX));
            uint        j    = (uint)((Random.value) * (float)(m_grid.nbCellsY));
            TDGrid.Cell cell = new TDGrid.Cell();
            cell.m_i = i;
            cell.m_j = j;
            if (m_grid.cellState(cell) != TDGrid.CellState.eFree)
            {
                continue;
            }
            Vector3 pos = m_grid.getCenter(cell);
            pos = from2dTo3d(pos);
            occupyPosition(pos, TDGrid.CellState.eBusy);
            addTree(pos);
            treesBuilt++;
        }
    }
示例#2
0
    void Awake()
    {
        m_strategy = new TDTowerStrategy();
        m_configuration = new TDConfiguration();
        m_configuration.readFromResource();

        GameObject terrain = getTerrain();
        Bounds terrainBounds = terrain.renderer.bounds;
        Vector3 lowPnt = from3dTo2d(terrainBounds.min);
        Vector3 highPnt = from3dTo2d(terrainBounds.max);
        m_grid = new TDGrid();
        m_grid.initialize(m_configuration.gridNbCellsX, m_configuration.gridNbCellsY,
                          lowPnt.x, lowPnt.y, highPnt.x - lowPnt.x, highPnt.y - lowPnt.y);

        // Take into account obstacles
        GameObject [] aObstacles = getAllObstacles();
        foreach (GameObject obj in aObstacles)
        {
            TDGrid.CellState cellState = TDGrid.CellState.eBusy;
            switch (obj.tag)
            {
                case "Player":
                    cellState = TDGrid.CellState.ePlayer;
                    break;
                case "EnemyRespawn":
                    cellState = TDGrid.CellState.eEnemyRespawn;
                    break;
            }
            Bounds b = obj.renderer.bounds;
            occupyRegion(b.min, b.max, cellState);
        }

        // put the dynamic obstacles
        uint treesBuilt = 0;
        while (treesBuilt < m_configuration.nbTrees)
        {
            uint i = (uint)((Random.value)*(float)(m_grid.nbCellsX));
            uint j = (uint)((Random.value)*(float)(m_grid.nbCellsY));
            TDGrid.Cell cell = new TDGrid.Cell();
            cell.m_i = i;
            cell.m_j = j;
            if (m_grid.cellState(cell) != TDGrid.CellState.eFree)
                continue;
            Vector3 pos = m_grid.getCenter(cell);
            pos = from2dTo3d(pos);
            occupyPosition(pos, TDGrid.CellState.eBusy);
            addTree(pos);
            treesBuilt++;
        }
    }