Esempio n. 1
0
        protected override void Update(GameTime gameTime)
        {
            ms = Mouse.GetState();
            ks = Keyboard.GetState();

            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                _gameState.GameStateID = _gameState.MainMenu;
                resetGame();
            }

            if (_gameState.GameStateID == _gameState.GameActive)
            {
                updateShieldGenerators(gameTime);
                _headquartersShields.Update(gameTime);
                _shieldGensAlive = 0;
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorA, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorB, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorC, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorD, _shieldGensAlive);
                gameOver();

                #region Cheats
                var _cheatMaxMissiles = new KeyboardState(Keys.LeftControl, Keys.Q);
                var _cheatMaxShields = new KeyboardState(Keys.LeftControl, Keys.W);
                var _cheatMoreAsteroids = new KeyboardState(Keys.LeftControl, Keys.E);
                var _cheatdebugMode = new KeyboardState(Keys.LeftControl, Keys.R);
                var _cheatEndAsteroids = new KeyboardState(Keys.LeftControl, Keys.A);
                var _cheatScore = new KeyboardState(Keys.LeftControl, Keys.S);
                var _cheatBombs = new KeyboardState(Keys.LeftControl, Keys.D);
                var _changeGameModeUp = new KeyboardState(Keys.LeftControl, Keys.Up);
                var _changeGameModeDown = new KeyboardState(Keys.LeftControl, Keys.Down);

                    if (ks == _cheatMaxMissiles)
                    {
                        _missileStockPile = 999;
                    }
                    if (ks == _cheatMaxShields)
                    {
                        _headquartersShields.Health = 999;
                    }
                    if (ks == _cheatMoreAsteroids)
                    {
                        createAsteroids();
                    }
                    if (ks == _cheatEndAsteroids)
                    {
                        _asteroidsRemainingToSpawn = 0;
                        foreach (Asteroids a in _asteroids)
                        {
                            a.Alive = false;
                        }
                    }
                    if (ks == _changeGameModeUp)
                    {
                        _gameState.GameStateID++;
                    }
                    if (ks == _changeGameModeDown)
                    {
                        _gameState.GameStateID--;
                    }
                    if (ks == _cheatScore)
                    {
                        _score = 9999;
                    }
                    if (ks == _cheatBombs)
                    {
                        _bombsAvailable= 999;
                    }

                    if ((ks == _cheatdebugMode) && (_debugMode == false))
                        _debugMode = true;
                    else if ((ks == _cheatdebugMode)&& (_debugMode == true))
                        _debugMode = false;
                #endregion

                #region Missile Firing Logic
                if ((ms.LeftButton == ButtonState.Pressed) && (msPrevious.LeftButton == ButtonState.Released) && (_missileStockPile >=1))
                {
                    var MousePosition = new Vector2();
                    MousePosition.X = ms.X;
                    MousePosition.Y = ms.Y;
                    Vector2 hqPosition;
                    hqPosition.X = _hqBB.X + (_hq.Width );
                    hqPosition.Y = _hqBB.Y;
                    createMissiles(MousePosition, hqPosition);
                    _missileStockPile--;
                }
                if ((ms.RightButton == ButtonState.Pressed) && (msPrevious.RightButton == ButtonState.Released) && (_bombsAvailable >= 1))
                {
                    for (int i = _asteroids.Count() - 1; i >= 0; i--)
                    {
                        _score += 10;
                        _asteroidsKilled++;

                    }
                    foreach (Asteroids a in _asteroids)
                    {
                        a.Alive = false;
                    }
                    _bombsAvailable--;
                }

                msPrevious = ms;
                #endregion
                if ((spawnAsteroid <0) && (_asteroidsRemainingToSpawn >0 ))
                {
                    createAsteroids();
                    _asteroidsRemainingToSpawn--;
                    spawnAsteroid = 50;
                }
                spawnAsteroid--;
                #region Collision Detection
                _shieldGeneratorA.generatorCollisionDetection(_asteroids);
                _shieldGeneratorB.generatorCollisionDetection(_asteroids);
                _shieldGeneratorC.generatorCollisionDetection(_asteroids);
                _shieldGeneratorD.generatorCollisionDetection(_asteroids);
                _headquartersShields.shieldCollisionDetection(_asteroids);
                foreach (var a in _asteroids)
                {
                    if (a.BoundingBox.Intersects(_hqBB))
                    {
                        if ((_headquarters.Alive) && (_headquartersShields.Alive != true))
                        {
                            a.Alive = false;
                            _headquarters.Alive = false;
                        }
                    }

                    foreach (var e in _explosions)
                    {

                        if (e.BoundingBox.Intersects(a.BoundingBox))
                        {
                            a.Alive = false;
                            _score += 10;
                            _asteroidsKilled++;
                        }
                    }
                }
                #endregion
                #region Missile Explosions
                foreach (var m in _missiles)
                {
                    if (m.Explosion == true)
                    {
                        var tempExplosion = new Explosions(this, spriteBatch, graphics.GraphicsDevice.Viewport.TitleSafeArea, m.Position);
                        _explosions.Add(tempExplosion);
                        Components.Add(tempExplosion);
                    }
                }
                #endregion
                garbageCollection();

            }
            checkIfWaveComplete();
            base.Update(gameTime);
        }
Esempio n. 2
0
        protected override void Update(GameTime gameTime)
        {
            ms = Mouse.GetState();
            ks = Keyboard.GetState();

            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                _gameState.GameStateID = _gameState.MainMenu;
                resetGame();
            }


            if (_gameState.GameStateID == _gameState.GameActive)
            {
                updateShieldGenerators(gameTime);
                _headquartersShields.Update(gameTime);
                _shieldGensAlive = 0;
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorA, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorB, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorC, _shieldGensAlive);
                _shieldGensAlive = totalShieldGeneratorsAlive(_shieldGeneratorD, _shieldGensAlive);
                gameOver();

                #region Cheats
                var _cheatMaxMissiles   = new KeyboardState(Keys.LeftControl, Keys.Q);
                var _cheatMaxShields    = new KeyboardState(Keys.LeftControl, Keys.W);
                var _cheatMoreAsteroids = new KeyboardState(Keys.LeftControl, Keys.E);
                var _cheatdebugMode     = new KeyboardState(Keys.LeftControl, Keys.R);
                var _cheatEndAsteroids  = new KeyboardState(Keys.LeftControl, Keys.A);
                var _cheatScore         = new KeyboardState(Keys.LeftControl, Keys.S);
                var _cheatBombs         = new KeyboardState(Keys.LeftControl, Keys.D);
                var _changeGameModeUp   = new KeyboardState(Keys.LeftControl, Keys.Up);
                var _changeGameModeDown = new KeyboardState(Keys.LeftControl, Keys.Down);

                if (ks == _cheatMaxMissiles)
                {
                    _missileStockPile = 999;
                }
                if (ks == _cheatMaxShields)
                {
                    _headquartersShields.Health = 999;
                }
                if (ks == _cheatMoreAsteroids)
                {
                    createAsteroids();
                }
                if (ks == _cheatEndAsteroids)
                {
                    _asteroidsRemainingToSpawn = 0;
                    foreach (Asteroids a in _asteroids)
                    {
                        a.Alive = false;
                    }
                }
                if (ks == _changeGameModeUp)
                {
                    _gameState.GameStateID++;
                }
                if (ks == _changeGameModeDown)
                {
                    _gameState.GameStateID--;
                }
                if (ks == _cheatScore)
                {
                    _score = 9999;
                }
                if (ks == _cheatBombs)
                {
                    _bombsAvailable = 999;
                }


                if ((ks == _cheatdebugMode) && (_debugMode == false))
                {
                    _debugMode = true;
                }
                else if ((ks == _cheatdebugMode) && (_debugMode == true))
                {
                    _debugMode = false;
                }
                #endregion

                #region Missile Firing Logic
                if ((ms.LeftButton == ButtonState.Pressed) && (msPrevious.LeftButton == ButtonState.Released) && (_missileStockPile >= 1))
                {
                    var MousePosition = new Vector2();
                    MousePosition.X = ms.X;
                    MousePosition.Y = ms.Y;
                    Vector2 hqPosition;
                    hqPosition.X = _hqBB.X + (_hq.Width);
                    hqPosition.Y = _hqBB.Y;
                    createMissiles(MousePosition, hqPosition);
                    _missileStockPile--;
                }
                if ((ms.RightButton == ButtonState.Pressed) && (msPrevious.RightButton == ButtonState.Released) && (_bombsAvailable >= 1))
                {
                    for (int i = _asteroids.Count() - 1; i >= 0; i--)
                    {
                        _score += 10;
                        _asteroidsKilled++;
                    }
                    foreach (Asteroids a in _asteroids)
                    {
                        a.Alive = false;
                    }
                    _bombsAvailable--;
                }

                msPrevious = ms;
                #endregion
                if ((spawnAsteroid < 0) && (_asteroidsRemainingToSpawn > 0))
                {
                    createAsteroids();
                    _asteroidsRemainingToSpawn--;
                    spawnAsteroid = 50;
                }
                spawnAsteroid--;
                #region Collision Detection
                _shieldGeneratorA.generatorCollisionDetection(_asteroids);
                _shieldGeneratorB.generatorCollisionDetection(_asteroids);
                _shieldGeneratorC.generatorCollisionDetection(_asteroids);
                _shieldGeneratorD.generatorCollisionDetection(_asteroids);
                _headquartersShields.shieldCollisionDetection(_asteroids);
                foreach (var a in _asteroids)
                {
                    if (a.BoundingBox.Intersects(_hqBB))
                    {
                        if ((_headquarters.Alive) && (_headquartersShields.Alive != true))
                        {
                            a.Alive             = false;
                            _headquarters.Alive = false;
                        }
                    }

                    foreach (var e in _explosions)
                    {
                        if (e.BoundingBox.Intersects(a.BoundingBox))
                        {
                            a.Alive = false;
                            _score += 10;
                            _asteroidsKilled++;
                        }
                    }
                }
                #endregion
                #region Missile Explosions
                foreach (var m in _missiles)
                {
                    if (m.Explosion == true)
                    {
                        var tempExplosion = new Explosions(this, spriteBatch, graphics.GraphicsDevice.Viewport.TitleSafeArea, m.Position);
                        _explosions.Add(tempExplosion);
                        Components.Add(tempExplosion);
                    }
                }
                #endregion
                garbageCollection();
            }
            checkIfWaveComplete();
            base.Update(gameTime);
        }