Пример #1
0
        // Update
        protected override void Update(GameTime gameTime)
        {
            Input.Update();
            // The above must be called for Input data to update per frame, this allows us to instead of:
            // if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            // we can use:
            if (Input.IsButtonDown(Buttons.Back) || Input.WasKeyPressed(Keys.Escape))
            {
                this.Exit();
            }

            UiButtonMessenger.ButtonResponder(Input.GetMouseState, Input.GetMouseStateOld);

            if (GameManager.GameState == GameManager.GameStates.StartScreen)
            {
                if (Input.LMBDown)
                {
                    GameManager.GameState = GameManager.GameStates.PlayScreen;
                }
            }

            if (GameManager.GameState == GameManager.GameStates.PlayScreen)
            {
                GameManager.Update(gameTime);
                // Using the last button pressed ID, as long as it exists,
                // see if it is a "btn0" and then set the BuildState using the rest of the ID.
                if (UiButtonMessenger.ButtonPressedId != null)
                {
                    if (UiButtonMessenger.ButtonPressedId.Contains("btn0"))
                    {
                        // Create String from id by removing the "btn0". Then Parse String to enum.
                        string bStateString = UiButtonMessenger.ButtonPressedId.Substring(4);
                        GameManager.BuildState = (GameManager.BuildStates)Enum.Parse(typeof(GameManager.BuildStates), bStateString);
                    }
                    else if (UiButtonMessenger.ButtonPressedId.Contains("btn1"))
                    {
                        // Create String from id by removing the "btn0". Then Parse String to enum.
                        string bStateString = UiButtonMessenger.ButtonPressedId.Substring(4);
                        WaveManager.StartWave();
                    }
                }
                GameManager.grid.Update(gameTime);

                for (int y = 0; y < GameManager.HEIGHT; y++) // get if a square has been edited
                {
                    for (int x = 0; x < GameManager.WIDTH; x++)
                    {
                        if (GameManager.grid.gridSquares[x, y].getSquareEdited)
                        {
                            EnemyManager.ResetEnemyAI();
                            GameManager.grid.pathFound = false;
                            GameManager.grid.pathFound = GridManager.GridPaths(GameManager.grid.gridSquares);
                        }
                    }
                }
                base.Update(gameTime);
            }
        }
Пример #2
0
        // Update
        protected override void Update(GameTime gameTime)
        {
            targetTime = this.TargetElapsedTime;

            if (Input.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad0))
            {
                this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 180.0f);
                SpeedUp = true;
            }
            else
            {
                SpeedUp = false;
                this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60.0f);
            }


            Input.Update();
            // The above must be called for Input data to update per frame, this allows us to instead of:
            // if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            // we can use:
            if (Input.IsButtonDown(Buttons.Back) || Input.WasKeyPressed(Keys.Escape) || exit)
            {
                this.Exit();
            }



            UiButtonMessenger.ButtonResponder(Input.GetMouseState, Input.GetMouseStateOld);

            if (GameManager.GameState == GameManager.GameStates.StartScreen || startScreen.fadeout)
            {
                startScreen.Update(gameTime);
            }

            if (GameManager.GameState == GameManager.GameStates.InfoScreen)
            {
                infoScreen.Update();
            }

            if (GameManager.GameState == GameManager.GameStates.LoseScreen || endScreen.fadeout)
            {
                endScreen.Update(gameTime);
            }

            if (resetgame)
            {
                ResetGame();
                resetgame = false;
            }

            if (GameManager.GameState == GameManager.GameStates.PlayScreen || endScreen.fadein)
            {
                GameManager.Update(gameTime);
                // Using the last button pressed ID, as long as it exists,
                // see if it is a "btn0" and then set the BuildState using the rest of the ID.
                if (UiButtonMessenger.ButtonPressedId != null)
                {
                    if (UiButtonMessenger.ButtonPressedId.Contains("btn0"))
                    {
                        // Create String from id by removing the "btn0". Then Parse String to enum.
                        string bStateString = UiButtonMessenger.ButtonPressedId.Substring(4);
                        GameManager.BuildState = (GameManager.BuildStates)Enum.Parse(typeof(GameManager.BuildStates), bStateString);
                    }
                    else if (UiButtonMessenger.ButtonPressedId.Contains("btn1") && !QuestionPopUpManager.QuestionUp && !MessageBoxManager.MessageDisplayed)
                    {
                        // Create String from id by removing the "btn0". Then Parse String to enum.
                        string bStateString = UiButtonMessenger.ButtonPressedId.Substring(4);
                        WaveManager.StartWave();
                    }
                }

                GameManager.grid.Update(gameTime);

                for (int y = 0; y < GameManager.HEIGHT; y++) // get if a square has been edited
                {
                    for (int x = 0; x < GameManager.WIDTH; x++)
                    {
                        if (GameManager.grid.gridSquares[x, y].getSquareEdited)
                        {
                            EnemyManager.ResetEnemyAI();
                            GameManager.grid.pathFound = false;
                            GameManager.grid.pathFound = GridManager.GridPaths(GameManager.grid.gridSquares);
                        }
                    }
                }

                base.Update(gameTime);
            }

            if (GameManager.GameState == GameManager.GameStates.StartVideo)
            {
                if (GameManager.FIRSTRUN)
                {
                    GameManager.videoPlayer.Play(Art.StartVideo);
                    GameManager.FIRSTRUN = false;
                }
                if (GameManager.videoPlayer.State == MediaState.Stopped || Input.LMBDown)
                {
                    GameManager.GameState = GameManager.GameStates.StartScreen;
                    GameManager.videoPlayer.Stop();
                    PlayMusic();
                }
            }

            if (GameManager.GameState == GameManager.GameStates.TutScreen)
            {
                GameManager.videoPlayer.Play(Art.TutVideo);
                if (GameManager.videoPlayer.State == MediaState.Stopped || Input.WasLMBClicked)
                {
                    GameManager.GameState = GameManager.GameStates.StartScreen;
                    GameManager.videoPlayer.Stop();
                }
            }
        }