IEnumerator SpawnWaves()
    {
        waveNum = 0;

        while (true)
        {
            waveNum++;

            if (waveEvents.ContainsKey(waveNum))
            {
                waveEvents[waveNum].Invoke();
            }

            WaveSetting wave = SelectWave(waveNum);

            Debug.Log("Begin Wave " + waveNum + " (" + wave.Name + ")");

            OnRoundBegin?.Invoke(waveNum);
            waveInfoController.WaveNum = waveNum;

            //AlertText(wave.Name, Color.magenta);

            wave.WaveCallable?.Invoke();

            ScaledWave scaledWave = new ScaledWave(wave, Mathf.Pow(enemyScaleBase, waveNum - 1));

            while (scaledWave.HasEnemies)
            {
                List <GameObject> nextSet = scaledWave.GetNextSpawn();

                // single tick
                foreach (GameObject prefab in nextSet)
                {
                    // single spawn
                    GameObject newEnemy = Instantiate(prefab, Vector3.zero, Quaternion.identity);
                    enemiesSpawnedInWave.Enqueue(newEnemy);

                    yield return(new WaitForSeconds((timePerTick * Mathf.Pow(tickScaleBase, waveNum - 1)) / nextSet.Count));
                }

                yield return(new WaitForSeconds(timeBetweenTicks * Mathf.Pow(tickScaleBase, waveNum - 1)));
            }

            while (enemiesSpawnedInWave.Count > 0)
            {
                while (enemiesSpawnedInWave.Count > 0 && enemiesSpawnedInWave.Peek() == null)
                {
                    enemiesSpawnedInWave.Dequeue();
                }

                yield return(new WaitForSeconds(.5f));
            }

            OnRoundEnd?.Invoke(waveNum);

            waveInfoController.StartTimer(timeBetweenWaves);

            yield return(new WaitForSeconds(timeBetweenWaves));
        }
    }
    private void GameManager_OnGameStateChange(EGameStates GameState)
    {
        switch (GameState)
        {
        case EGameStates.MAIN_MENU:
            OnMainMenu?.Invoke();
            break;

        case EGameStates.CONNECTING:
            break;

        case EGameStates.RELOADING_ROUND:
            break;

        case EGameStates.LOADING_NEXTROUND:
            OnRoundBegin.Invoke();
            break;

        case EGameStates.LOADING_REMATCH:
            break;

        case EGameStates.GAMEPLAY:
            OnGameplayBegin?.Invoke();
            break;

        case EGameStates.ROUND_OVER:
            OnRoundOver.Invoke();
            break;

        case EGameStates.GAME_OVER:
            OnGameOver.Invoke();
            break;
        }
    }
Ejemplo n.º 3
0
        private void OnTimeOut()
        {
            _countDown--;

            if (_countDown < -1)
            {
                OnCountdownHandler?.Invoke(_countDown);
                _countDownTimer.Stop();
            }
            else if (_countDown < 0)
            {
                OnCountdownHandler?.Invoke(_countDown);
                OnRoundBeginHandler.Invoke(_number);
                _timer.Start();
                _timer.OnTimeLimitHandler += OnRoundEnd;
                return;
            }
            else
            {
                OnCountdownHandler?.Invoke(_countDown);
            }
        }
Ejemplo n.º 4
0
        public void SetRoundBegin()
        {
            ChangeGameState(EGameStates.GAMEPLAY);

            OnRoundBegin.Invoke();
        }