Пример #1
0
        // This uses the loading screen to transition from the game back to the main menu screen.
        private void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            MainMenuScreen mms = new MainMenuScreen(_game);

            mms.ContentPasser(new ContentManager(ScreenManager.Game.Services, "Content"));

            LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), mms);
        }
Пример #2
0
        /// <summary>
        /// Is called when the screen is active
        /// </summary>
        /// <param name="gameTime">The game's time</param>
        /// <param name="input">The input state object</param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            var keyboardState = input.CurrentKeyboardStates[playerIndex];
            var gamePadState  = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex];

            PlayerIndex player;

            if (_pauseAction.Occurred(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(_game), ControllingPlayer);
            }
            else
            {
                //Levels state machine
                switch (levelState)
                {
                case LevelState.Start:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        levelState = LevelState.Zero;
                    }
                    break;

                case LevelState.Zero:
                    level0.Update(gameTime);
                    if (level0.Won)
                    {
                        levelTransport.Play();
                        levelState = LevelState.One;
                        level1     = new Level1(level0.HP, ScreenManager.StoredGame);
                        LoadState();
                    }
                    if (level0.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.One:
                    level1.Update(gameTime);
                    if (level1.Won)
                    {
                        levelTransport.Play();
                        levelState = LevelState.Two;
                        level2     = new Level2(level1.HP, ScreenManager.StoredGame);
                        LoadState();
                    }
                    if (level1.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.Two:
                    level2.Update(gameTime);
                    if (level2.Won)
                    {
                        levelComplete.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndW;
                    }
                    if (level2.Lost)
                    {
                        lose.Play();
                        _time      = gameTime.TotalGameTime.ToString();
                        levelState = LevelState.EndL;
                    }
                    break;

                case LevelState.EndW:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        MainMenuScreen mms = new MainMenuScreen(_game);
                        mms.ContentPasser(_content);

                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), mms);
                    }
                    break;

                case LevelState.EndL:
                    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                    {
                        MainMenuScreen mms = new MainMenuScreen(_game);
                        mms.ContentPasser(_content);

                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), mms);
                    }
                    break;
                }
            }
        }