コード例 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            #region PADCONTROL
            // Allows the game to exit
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            /*if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
             *  colorin = Color.Green;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
             *  colorin = Color.Red;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed)
             *  colorin = Color.Yellow;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed)
             *  colorin = Color.Blue;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.RightShoulder == ButtonState.Pressed)
             *  colorin = Color.Violet;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
             *  colorin = Color.Purple;
             * if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
             *  colorin = Color.White;
             * if (GamePad.GetState(PlayerIndex.One).Triggers.Right == 1f)
             *  colorin = Color.Pink;
             * if (GamePad.GetState(PlayerIndex.One).Triggers.Left == 1f)
             *  colorin = Color.Orange;
             * /*     if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
             *  colorin = Color.Orchid;
             * if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
             *  colorin = Color.Maroon;
             * if (GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
             *  colorin = Color.Gold;
             * if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
             *  colorin = Color.Cyan;*/
            #endregion
            // TODO: Add your update logic here

            DoLogic();

            int            count         = 0;
            int            countInvasor  = 0;
            int            countComplete = 0;
            int            countShoot    = 0;
            int            countTank     = 0;
            List <Invasor> list          = new List <Invasor>();

            #region CONTADOR COMPONENTES
            foreach (GameComponent gc in Components)
            {
                if (gc is Background)
                {
                    count++;
                }
                if (gc is Shoot)
                {
                    countShoot++;
                }
                if (gc is Invasor)
                {
                    countInvasor++;
                    if (countInvasor == 1 &&
                        ((Invasor)gc).die)
                    {
                        // countInvasor = 0;
                        //    list.Add((Invasor)gc);
                    }
                }
                if (gc is Tank)
                {
                    countTank++;
                }
            }
            if (countTank == 0)
            {
                player = new Tank(this, ref tank, screen);
                Components.Add(player);
                player.PutinStartPosition();
            }

            if (count == 0)
            {
                Exit();
            }
            if (countInvasor == 0)
            {
                //countComplete++;
                countComplete = 1;
                invasorsManager.SheetInvaders(this, ref invasor);
                #region SELECT DIFFICULTY
                switch (countComplete)
                {
                case 1:
                {
                    invasorsManager.SelectDifficult(difficult.normal.ToString());
                    break;
                }

                case 2:
                {
                    invasorsManager.SelectDifficult(difficult.hard.ToString());
                    break;
                }

                default:
                {
                    invasorsManager.SelectDifficult(difficult.insane.ToString());
                    break;
                }
                }
                #endregion
            }

            #endregion

            if (ufoBonus)
            {
                UfoBonusYes();
            }

            base.Update(gameTime);
        }