Esempio n. 1
0
        /// <summary>
        /// Allows the page to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        private void OnUpdate(object sender, GameTimerEventArgs e)
        {
            _leftBaseCoolDown.Update();
            _rightBaseCoolDown.Update();
            _middleBaseCoolDown.Update();

            //lose check
            if (_buildings[0].GetDeathState && _buildings[1].GetDeathState && _buildings[2].GetDeathState && _buildings[3].GetDeathState && _buildings[4].GetDeathState && _buildings[5].GetDeathState)
            {
                _lose = true;
                TextBlockFinalScores.Text = _score.ToString();
                CanvasGameOver.Visibility = System.Windows.Visibility.Visible;
            }
            if (_leftBase.GetDeathState && _middleBase.GetDeathState && _rightBase.GetDeathState)
            {
                _lose = true;
                TextBlockFinalScores.Text = _score.ToString();
                CanvasGameOver.Visibility = System.Windows.Visibility.Visible;
            }

            //mini buildings to test collisions
            for (int i = 0; i < _buildings.Length; i++)
            {
                if (!_buildings[i].GetDeathState)
                {
                    if (_missileManager.TestForMissileRectangleCollisions(_buildings[i].GetRectangle))
                    {
                        _city -= 1;
                        _percentMultiplier -= 0.1f;
                        UpdateOverlay();
                        _buildings[i].Destruction(Missile.missileManager.GetLandScape, 30, 30);
                    }
                }
            }

            //missile manager testcollision with buildings
            if (!_leftBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_leftBase.GetRectangle))
                {
                    BorderLeftArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missilesBases     -= 1;
                    _percentMultiplier -= 0.05f;
                    _leftBase.Destruction(Missile.missileManager.GetLandScape, 40, 30);

                    UpdateOverlay();
                }
            }
            if (!_middleBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_middleBase.GetRectangle))
                {
                    BorderMiddleArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missilesBases     -= 1;
                    _percentMultiplier -= 0.05f;
                    _middleBase.Destruction(Missile.missileManager.GetLandScape, 30, 30);

                    UpdateOverlay();
                }
            }
            if (!_rightBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_rightBase.GetRectangle))
                {
                    BorderRightArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missilesBases     -= 1;
                    _percentMultiplier -= 0.05f;
                    _rightBase.Destruction(Missile.missileManager.GetLandScape, 30, 30);
                    UpdateOverlay();
                }
            }

            TouchCollection touchCollection = TouchPanel.GetState();

            foreach (TouchLocation tl in touchCollection)
            {
                if (tl.State == TouchLocationState.Released)
                {
                    if (tl.Position.Y < (int)SharedGraphicsDeviceManager.DefaultBackBufferHeight - 40)
                    {
                        if (tl.Position.Y < HEIGHT - 50)
                        {
                            //adds a missile to the world
                            if (_selectedArrow == 1)
                            {
                                if (!_rightBaseCoolDown.IsOverHeated())
                                {
                                    if (!_rightBase.GetDeathState)
                                    {
                                        _rightBaseCoolDown.AddHeat(30);
                                        Missile.missileManager.Addmissile(new Vector2(_rightBase.GetRectangle.Left + _rightBase.GetRectangle.Width / 2, _rightBase.GetRectangle.Bottom - 2), tl.Position, new Missile.Player.PlayerNormalmissile());
                                    }
                                }
                            }
                            else if (_selectedArrow == 2)
                            {
                                if (!_middleBaseCoolDown.IsOverHeated())
                                {
                                    if (!_middleBase.GetDeathState)
                                    {
                                        _middleBaseCoolDown.AddHeat(30);
                                        Missile.missileManager.Addmissile(new Vector2(_middleBase.GetRectangle.Left + _middleBase.GetRectangle.Width / 2, _middleBase.GetRectangle.Bottom - 2), tl.Position, new Missile.Player.PlayerNormalmissile());
                                    }
                                }
                            }
                            else
                            {
                                if (!_leftBaseCoolDown.IsOverHeated())
                                {
                                    if (!_leftBase.GetDeathState)
                                    {
                                        _leftBaseCoolDown.AddHeat(30);
                                        Missile.missileManager.Addmissile(new Vector2(_leftBase.GetRectangle.Left + _leftBase.GetRectangle.Width / 2, _leftBase.GetRectangle.Bottom - 2), tl.Position, new Missile.Player.PlayerNormalmissile());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            _line.Update();
            // TODO: Add your update logic here
            _missileManager.Update();

            if (_oldScore != _score)
            {
                _oldScore = _score;
                UpdateOverlay();
            }
        }
Esempio n. 2
0
        public void update(LayerManager layerManager)
        {
            _mouse = Mouse.GetState();


            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                this._selectedArrow = 3;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                this._selectedArrow = 2;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                this._selectedArrow = 1;
            }

            _leftBaseCoolDown.Update();
            _rightBaseCoolDown.Update();
            _middleBaseCoolDown.Update();

            //lose check
            if (_buildings[0].GetDeathState && _buildings[1].GetDeathState && _buildings[2].GetDeathState && _buildings[3].GetDeathState && _buildings[4].GetDeathState && _buildings[5].GetDeathState)
            {
                _lose = true;
                //TextBlockFinalScores.Text = _score.ToString();
                //CanvasGameOver.Visibility = System.Windows.Visibility.Visible;
            }
            if (_leftBase.GetDeathState && _middleBase.GetDeathState && _rightBase.GetDeathState)
            {
                _lose = true;
                // TextBlockFinalScores.Text = _score.ToString();
                // CanvasGameOver.Visibility = System.Windows.Visibility.Visible;
            }

            //mini buildings to test collisions
            for (int i = 0; i < _buildings.Length; i++)
            {
                if (!_buildings[i].GetDeathState)
                {
                    if (_missileManager.TestForMissileRectangleCollisions(_buildings[i].GetRectangle))
                    {
                        _city -= 1;
                        _percentMultiplier -= 0.1f;

                        _buildings[i].Destruction(missileCommand.Missile.missileManager.GetLandScape, 30, 30);
                    }
                }
            }

            //missile manager testcollision with buildings
            if (!_leftBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_leftBase.GetRectangle))
                {
                    //BorderLeftArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missileBases      -= 1;
                    _percentMultiplier -= 0.05f;
                    _leftBase.Destruction(missileCommand.Missile.missileManager.GetLandScape, 40, 30);
                }
            }
            if (!_middleBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_middleBase.GetRectangle))
                {
                    // BorderMiddleArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missileBases      -= 1;
                    _percentMultiplier -= 0.05f;
                    _middleBase.Destruction(missileCommand.Missile.missileManager.GetLandScape, 30, 30);
                }
            }
            if (!_rightBase.GetDeathState)
            {
                if (_missileManager.TestForMissileRectangleCollisions(_rightBase.GetRectangle))
                {
                    //BorderRightArrow.Visibility = System.Windows.Visibility.Collapsed;

                    _missileBases      -= 1;
                    _percentMultiplier -= 0.05f;
                    _rightBase.Destruction(missileCommand.Missile.missileManager.GetLandScape, 30, 30);
                }
            }

            if (_isInPlay)
            {
                if (_mouse.LeftButton == ButtonState.Pressed && _oldState == ButtonState.Released)
                {
                    if (_mouse.Position.Y < Game1.game.GraphicsDevice.Viewport.Height - 40)
                    {
                        if (_mouse.Position.Y < Game1.game.GraphicsDevice.Viewport.Height - 50)
                        {
                            //adds a missile to the world
                            if (_selectedArrow == 1)
                            {
                                if (!_rightBaseCoolDown.IsOverHeated())
                                {
                                    if (!_rightBase.GetDeathState)
                                    {
                                        _rightBaseCoolDown.AddHeat(30);


                                        _missileManager.Addmissile(new Vector2(_rightBase.GetRectangle.Left + _rightBase.GetRectangle.Width / 2, _rightBase.GetRectangle.Bottom - 2), _mouse.Position.ToVector2(), new PlayerNormalmissile(_missileManager));
                                    }
                                }
                            }
                            else if (_selectedArrow == 2)
                            {
                                if (!_middleBaseCoolDown.IsOverHeated())
                                {
                                    if (!_middleBase.GetDeathState)
                                    {
                                        _middleBaseCoolDown.AddHeat(30);
                                        _missileManager.Addmissile(new Vector2(_middleBase.GetRectangle.Left + _middleBase.GetRectangle.Width / 2, _middleBase.GetRectangle.Bottom - 2), _mouse.Position.ToVector2(), new PlayerNormalmissile(_missileManager));
                                    }
                                }
                            }
                            else
                            {
                                if (!_leftBaseCoolDown.IsOverHeated())
                                {
                                    if (!_leftBase.GetDeathState)
                                    {
                                        _leftBaseCoolDown.AddHeat(30);

                                        _missileManager.Addmissile(new Vector2(_leftBase.GetRectangle.Left + _leftBase.GetRectangle.Width / 2, _leftBase.GetRectangle.Bottom - 2), _mouse.Position.ToVector2(), new PlayerNormalmissile(_missileManager));
                                    }
                                }
                            }
                        }
                    }
                }
            }


            if ((_missileBases <= 0 || _city <= 0) && _isInPlay)
            {
                if (layerManager.getLayerById("game-over") == null)
                {
                    layerManager.addLayer(new GameOver(_score));
                }
            }



            _oldState = _mouse.LeftButton;

            _line.Update();
            // TODO: Add your update logic here
            _missileManager.Update(this);
        }