Example #1
0
        public override void Update(GameTime gameTime)
        {
            if (_score.PeopleKilled < _building.Persons.Count())
            {
                _timer -= gameTime.ElapsedGameTime;
            }

            _building.Update(gameTime);
            _score.Update(gameTime);

            if (_timer <= TimeSpan.Zero)
            {
                GameOverScene go = ((GameOverScene)Handler.Scenes[(int)SceneNames.GameOverScene]);
                go.RefreshScore(_currentDifficulty);
                Handler.SwitchToScene((int)SceneNames.GameOverScene);
            }
            else if (_score.PeopleKilled >= _building.Persons.Count())
            {
                _delayTimer += gameTime.ElapsedGameTime;

                if (_delayTimer > new TimeSpan(0, 0, 3))
                {
                    ResultScene resultScene = (ResultScene)Handler.Scenes[(int)SceneNames.ResultScene];
                    resultScene.RefreshScore(_score, _timer, _currentDifficulty);
                    Handler.SwitchToScene((int)SceneNames.ResultScene);
                }
            }

            LinkedList <Cloud> _disposeList = new LinkedList <Cloud>();

            //clouds
            foreach (Cloud cloud in _clouds)
            {
                cloud.Update(gameTime);
                if (cloud.Dispose)
                {
                    _disposeList.AddLast(cloud);
                }
            }

            foreach (Cloud cloud in _disposeList)
            {
                _clouds.Remove(cloud);
            }


            _currentCloudTimer += gameTime.ElapsedGameTime;
            if (_currentCloudTimer > _cloudSpawnTimer)
            {
                Cloud cloud = new Cloud(Game);
                _clouds.Add(cloud);
                _cloudSpawnTimer   = new TimeSpan(0, 0, RandomHelper.RandomInt(30, 60));
                _currentCloudTimer = TimeSpan.Zero;
            }
        }