コード例 #1
0
ファイル: GameManager.cs プロジェクト: AkirAssasin/ld48
    // populate a corridor (assumed empty)
    void GenerateCorridorContent(Corridor corridor, int depth)
    {
        // generate list of cells
        List <int> unoccupiedCells = new List <int>();

        for (int i = 0; i < corridor.Length; ++i)
        {
            unoccupiedCells.Add(i);
        }

        // populate with enemies
        if (depth > 0)
        {
            // how many enemies to add
            int enemyCount = Mathf.Clamp(1 + depth / 4, 1, 2);
            for (int i = 0; i < enemyCount; ++i)
            {
                // choose random cell
                int r = Random.Range(0, unoccupiedCells.Count);

                // add enemy
                EnemyActorController enemy = EnemyActorController.GetFromPool(s_gameSettings.enemyPrefab);
                enemy.Initialize(this, depth, unoccupiedCells[r], false);

                // remove chosen cell
                unoccupiedCells.RemoveAt(r);
            }
        }

        // add some doors
        int doorCount = Random.Range(-1, Mathf.Clamp(depth, 0, 3));

        for (int i = 0; i < doorCount; ++i)
        {
            // choose random cell
            int r     = Random.Range(0, unoccupiedCells.Count);
            int rCell = unoccupiedCells[r];

            // set as door
            corridor.SetWallState(WallState.Door, rCell);

            // add ambush here
            m_ambushes.Add(new AmbushEnemyInfo(depth, rCell, Random.Range(m_ambushMinTime, m_ambushMaxTime)));

            // remove chosen cell
            unoccupiedCells.RemoveAt(r);
        }
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: AkirAssasin/ld48
    void GameUpdate(float dt)
    {
        // delete corridors above max
        int requiredTopDepth = m_playerActor.CurrentDepth - m_maxCorridorsAbove;

        if (m_topCorridorDepth < requiredTopDepth)
        {
            // hide title if top is removed
            if (m_topCorridorDepth == 0)
            {
                m_titleTextMesh.enabled = false;
            }

            for (int i = 0; i < requiredTopDepth - m_topCorridorDepth; ++i)
            {
                m_corridors[i].Pool();
            }
            m_corridors.RemoveRange(0, requiredTopDepth - m_topCorridorDepth);
            m_topCorridorDepth = requiredTopDepth;
        }

        // update all ambushes
        for (int i = m_ambushes.Count - 1; i >= 0; --i)
        {
            // discard if out of depth
            AmbushEnemyInfo ambush = m_ambushes[i];
            if (ambush.m_depth < m_topCorridorDepth)
            {
                m_ambushes.RemoveAt(i);
                continue;
            }

            // otherwise run normally
            if (ambush.m_active)
            {
                // if active, countdown until enemy spawn
                if (ambush.m_time > 0f)
                {
                    ambush.m_time -= dt;
                }
                else if (m_playerActor.CurrentCell != ambush.m_cell)
                {
                    // spawn enemy and remove ambush when countdown is over
                    EnemyActorController enemy = EnemyActorController.GetFromPool(s_gameSettings.enemyPrefab);
                    enemy.Initialize(this, ambush.m_depth, ambush.m_cell, true);
                    m_ambushes.RemoveAt(i);
                    continue;
                }
            }
            else if (m_playerActor.CurrentDepth > ambush.m_depth)
            {
                ambush.m_active = true;
            }
        }

        // update score
        if (m_playerActor.CurrentDepth > m_currentBestDepth)
        {
            m_currentBestDepth = m_playerActor.CurrentDepth;
            if (m_currentBestDepth > s_bestScore)
            {
                s_bestScore = m_currentBestDepth;
            }
            UpdateScore();
        }
    }