private void SpawnWave(int levelEventId, WaveData wave)
    {
        float        maxSpawnDelay = -1;
        int          enemyCounter  = 0;
        List <float> tempFloatList;

        for (int i = 0; i < matrixRows; i++)
        {
            switch (i)
            {
            case 0: tempFloatList = wave.row0; break;

            case 1: tempFloatList = wave.row1; break;

            case 2: tempFloatList = wave.row2; break;

            case 3: tempFloatList = wave.row3; break;

            case 4: tempFloatList = wave.row4; break;

            default: tempFloatList = new List <float>(); break;
            }

            for (int j = 0; j < matrixCols; j++)
            {
                if (tempFloatList[j] > 0)
                {
                    SpawnEnemy(enemySpawnMatrix[j][i], tempFloatList[j]);
                    enemyCounter++;
                    if (maxSpawnDelay < tempFloatList[j])
                    {
                        maxSpawnDelay = tempFloatList[j];
                    }
                }
            }
            StartCoroutine(ActivateWave(maxSpawnDelay));
        }
        currentWaveBehaviour = new WaveBehaviour(wave, enemyCounter, levelEventId);
        currentWaveBehaviour.OnWaveCleared = (lvlEvntId) =>
        {
            BusSystem.LevelEvents.LevelEventFinished(lvlEvntId);
            currentWaveBehaviour.OnWaveCleared = null;
        };
    }
Exemple #2
0
    void Update()
    {
        // Get the next wave
        if (currentWave == null && waves.Count > 0)
        {
            currentWave = waves.Dequeue();
        }

        if (currentWave != null)
        {
            // Start the wave if we haven't already
            if (currentWave.phase == WaveBehaviour.Phase.NotStarted)
            {
                StartCoroutine(currentWave.Begin());
            }

            // Update the StatusBar during the Countdown Phase
            // if (currentWave.phase == WaveBehaviour.Phase.Countdown) {
            //     statusBar.message = currentWave.quantity.ToString () + "×" + currentWave.attackerPrefab.name + " in " +
            //     currentWave.timeRemaining.ToString ("F1") + " seconds";
            //     statusBar.percent = currentWave.timeRemaining / currentWave.secondsBeforeStarting;
            // } else {
            //     statusBar.message = "";
            //     statusBar.percent = 0.0f;
            // }

            // Clear the currentWave if it has finished
            if (currentWave.phase == WaveBehaviour.Phase.Finished)
            {
                currentWave = null;
            }
        }

        if (!attackersDestroyed && waves.Count == 0 && currentWave == null && attackersInPlay == 0)
        {
            // If we have visited every wave,
            // there is no wave currently spawning,
            // and there are no attackers left on the board,
            // we must have won.
            attackersDestroyed = true;
            EventManager.TriggerEvent("AttackersDestroyed");
        }
    }
Exemple #3
0
    void RecallWave()
    {
        waveBehaviour = WaveBehaviour.None;

        foreach (GameObject enemy in enemies)
        {
            if (enemy.GetComponent <RandomMovement>() != null)
            {
                if (enemy.GetComponent <RandomMovement>().enabled)
                {
                    enemy.GetComponent <RandomMovement>().enabled = false;
                }
            }

            if (enemy.GetComponent <DataCollector>())
            {
                enemy.GetComponent <DataCollector>().SetTarget(spawnPoint.transform);
            }
            else
            {
                agent = enemy.GetComponent <NavMeshAgent>();
                agent.SetDestination(spawnPoint.transform.position);
                agent.stoppingDistance = 1f;
            }

            float distanceFromSpawn = Vector3.Distance(enemy.transform.position, spawnPoint.transform.position);
            if (distanceFromSpawn <= rangeFromSpawn)
            {
                GetFactionData(enemy);
                Destroy(enemy);
            }
        }

        if (enemies.Count == 0)
        {
            globalSpawn = false;
            globalTimer = 0;
            points.Clear();
        }
    }
Exemple #4
0
    void ChooseBehaviour()
    {
        if (availableBehaviours.Count == 1)
        {
            // Debug.Log("1 available behaviour");
            waveBehaviour = availableBehaviours[0];
        }

        else if (availableBehaviours.Count == 2)
        {
            // Debug.Log("2 available behaviours");
            //choose between available behaviours
            float randomNum;
            randomNum = Random.Range(0f, 1f);
            if (randomNum >= 0.3)
            {
                waveBehaviour = availableBehaviours[0];
            }
            else
            {
                waveBehaviour = availableBehaviours[1];
            }
        }
    }