public WaveGenerator(Game game) { _game = game; LoadWaves(); _cumulativeDifficulty = .5f; _nextWaveTimer = new Timer(TimerMode.CountDown, 1); _nextWaveTimer.Elapsed += delegate { if(!_waves.MoveNext()) { LoadWaves(); _waves.MoveNext(); } CurrentWave = NextWave; NextWave = (Wave)_waves.Current.Clone(); _nextSpawnTimer.ResetValue = CurrentWave.SpawnInterval * 60; _nextWaveTimer.ResetValue = CurrentWave.NextWaveDelay * 60; _nextWaveTimer.Reset(); if(WaveStarted != null) WaveStarted(CurrentWave, NextWave, 0); _cumulativeDifficulty += 0.35f; }; _nextWaveTimer.Ticked += delegate(Timer timer) { if(timer.Value < 10*60) { if(WaveCountdown != null) WaveCountdown(CurrentWave, NextWave, timer.Value/10+1); } }; _nextSpawnTimer = new Timer(TimerMode.CountDown, 1); _nextSpawnTimer.Elapsed += delegate { if(CurrentWave.Count > 0) { CurrentWave.Count--; var es = _game.Map.EnemySpawns[0]; SpawnUnit(CurrentWave.Unit, es.BlockX*32+16, es.BlockY*32+16, _cumulativeDifficulty); _nextSpawnTimer.Reset(); } }; }