Пример #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)
        {
            //this line will prevent updating game1 when we are in the Game Menu
            //Console.WriteLine("Game 1");


            if (isPlayGameSelected)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    PopInGameMenu = true;

                    //currentState = MenuState_;
                    isPlayGameSelected = false;
                    manager.pauseGame();
                }



                //deals with the inGameMenu popup
                if (PopInGameMenu)
                {
                    inGameMenu_.Update(gameTime, spriteBatch);
                }

                // TODO: Add your update logic here

                if (nextState != null)
                {
                    currentState = nextState;
                    nextState    = null;
                }


                //if only play button is selected start game manager
                if (isPlayGameSelected)
                {
                    MediaPlayer.Stop();
                    manager.Update(gameTime, spriteBatch);
                }
            }

            //deals with if we should quit to the main menu
            if (QuitToMain)
            {
                Console.WriteLine("in quit");
                currentState       = MenuState_;
                isPlayGameSelected = false;
                QuitToMain         = false;
            }

            currentState.Update(gameTime, spriteBatch);
            currentState.PostUpdate(gameTime);


            //manager.Update(gameTime);

            base.Update(gameTime);
        }
        public void update(GameTime gameTime, SpriteBatch spriteBatch, ref bool isSelectLevelPressed)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                game1Ref.PopInGameMenu_ = true;
            }



            if (!game1Ref.PopInGameMenu_)
            {
                if (LVLClicked)
                {
                    game1Ref.gameManager_.Update(gameTime, spriteBatch);
                    //also reset game status just in case
                    //game1Ref.gameManager_.resetGame();
                }
                else
                {
                    spriteBatch.Begin();
                    gameBackground.Update(gameTime);

                    foreach (var component in components)
                    {
                        component.Draw(gameTime, spriteBatch);
                        component.Update(gameTime);
                    }

                    spriteBatch.End();
                }
            }
            else
            {
                inGameMenu_.Update(gameTime, spriteBatch);
            }

            if (game1Ref.QuitToMain_)
            {
                Console.WriteLine("quitting");
                LVLClicked           = false;
                isSelectLevelPressed = false;
            }
        }