Exemple #1
0
        private void ProcessWave()
        {
            var currentWave = _wavesConfig.Waves[_currentWave];

            if (_timer[0] <= currentWave.WaveDelay)
            {
                _timer[0] += Time.deltaTime;
                return;
            }

            if (_timer[1] <= currentWave.Delays[_currentWaveSpawn])
            {
                _timer[1] += Time.deltaTime;
                return;
            }

            // Spawn current wave spawn enemy in spawn id
            _spawnerManager.SpawnEnemy(currentWave.SpawnIds[_currentWaveSpawn], currentWave.EnemyToSpawn[_currentWaveSpawn]);

            // Reset timer for next spawn
            _timer[1] = 0;
            _currentWaveSpawn++;

            if (_currentWaveSpawn >= currentWave.EnemyToSpawn.Length)
            {
                _nextState = WaveSequenceState.TransitionWave;
            }
        }
Exemple #2
0
        public void Initialize()
        {
            _active       = false;
            _currentWave  = 0;
            _currentState = WaveSequenceState.ProcessWave;
            _nextState    = WaveSequenceState.ProcessWave;

            // Initializing static methods state machine
            _states = new WaveSequenceStateDelegate[(int)WaveSequenceState.Count];
            _states[(int)WaveSequenceState.ProcessWave]    = ProcessWave;
            _states[(int)WaveSequenceState.TransitionWave] = Transition;

            // 0 - wave delay timer
            // 1 - wave spawn delay
            _timer = new float[2];
        }
Exemple #3
0
        private void Update()
        {
            if (!_active)
            {
                return;
            }

            if (_nextState == _currentState)
            {
                _states[(int)_currentState]();
            }
            else
            {
                _currentState = _nextState;
            }
        }
Exemple #4
0
        private void Transition()
        {
            // Transition wave
            _currentWave++;
            // Reset timers for next wave
            _timer[0]         = _timer[1] = 0;
            _currentWaveSpawn = 0;

            GenericEvent.Trigger(GenericEventType.WaveFinished, null);

            // Cycle option
            if (_cycle)
            {
                _currentWave %= _wavesConfig.Waves.Length;
                _nextState    = WaveSequenceState.ProcessWave;
            }
            else
            {
                _active = false;
                // Trigger level completed
                GenericEvent.Trigger(GenericEventType.LevelCompleted, null);
            }
        }