Example #1
0
        protected override void Update(GameTime gameTime)
        {
            inputState.Update();
            gameTicksPerSecond = this.TargetElapsedTime.Milliseconds / 1000.0f;

            switch (currentState)
            {
            case GameState.SplashScreen:
                if (inputState.MenuCancel)
                {
                    currentState = GameState.ExitScreen;
                }
                else
                {
                    currentState = GameState.TitleScreen;
                }

                break;

            case GameState.TitleScreen:
                titleScreen.NextPosition(gameTicksPerSecond);

                if (inputState.MenuSelect || inputState.MenuCancel)
                {
                    currentState = GameState.MainMenu;
                }

                break;

            case GameState.MainMenu:
                ResetGame();

                if (inputState.MenuCancel)
                {
                    currentState = GameState.TitleScreen;
                }

                if (inputState.MenuUp)
                {
                    mainMenuMode--;
                    if (mainMenuMode < MenuMode.SinglePlayer)
                    {
                        mainMenuMode = MenuMode.SinglePlayer;
                    }
                }
                if (inputState.MenuDown)
                {
                    mainMenuMode++;
                    if (mainMenuMode > MenuMode.Exit)
                    {
                        mainMenuMode = MenuMode.Exit;
                    }
                }
                if (inputState.MenuSelect)
                {
                    switch (mainMenuMode)
                    {
                    case MenuMode.MultiPlayer:
                        gameScreen.GameMode = GameMode.MultiPlayer;
                        currentState        = GameState.Running;
                        break;

                    case MenuMode.SinglePlayer:
                        gameScreen.GameMode = GameMode.SinglePlayer;
                        currentState        = GameState.Running;
                        break;

                    case MenuMode.Option:
                        currentState = GameState.SettingsMenu;
                        break;

                    case MenuMode.Exit:
                        currentState = GameState.ExitScreen;
                        break;
                    }
                }
                break;

            case GameState.SettingsMenu:
                if (inputState.MenuCancel)
                {
                    currentState = GameState.MainMenu;
                }

                if (inputState.MenuUp)
                {
                    optionMenuMode--;
                    if (optionMenuMode < OptionMode.AdjustScreen)
                    {
                        optionMenuMode = OptionMode.AdjustScreen;
                    }
                }

                if (inputState.MenuDown)
                {
                    optionMenuMode++;
                    if (optionMenuMode > OptionMode.MainMenu)
                    {
                        optionMenuMode = OptionMode.MainMenu;
                    }
                }

                if (inputState.MenuSelect)
                {
                    switch (optionMenuMode)
                    {
                    case OptionMode.AdjustScreen:
                        currentState = GameState.ScalingScreen;
                        break;

                    case OptionMode.MainMenu:
                        currentState = GameState.MainMenu;
                        break;
                    }
                }
                break;

            case GameState.ScalingScreen:
                if (inputState.MenuCancel)
                {
                    currentState = GameState.MainMenu;
                }

                if (inputState.DirectionUp)
                {
                    screenOffset.Y--;
                }

                if (inputState.DirectionDown)
                {
                    screenOffset.Y++;
                }

                if (inputState.DirectionLeft)
                {
                    screenOffset.X--;
                }

                if (inputState.DirectionRight)
                {
                    screenOffset.X++;
                }

                if (inputState.DirectionClick)
                {
                    screenOffset = screenOffsetOrigin;
                }

                if (inputState.OtherDirectionUp)
                {
                    scalingFactor -= .001f;
                }

                if (inputState.OtherDirectionDown)
                {
                    scalingFactor += .001f;
                }

                if (inputState.OtherDirectionLeft)
                {
                    scalingFactor -= .01f;
                }

                if (inputState.OtherDirectionRight)
                {
                    scalingFactor += .01f;
                }

                if (inputState.OtherDirectionClick)
                {
                    scalingFactor = scalingFactorOrigin;
                }

                if (inputState.MenuSelect)
                {
                    pongConfig.ScalingFactor = scalingFactor;
                    pongConfig.ScreenOffset  = screenOffset;
                    pongConfig.Save(GetStorageDevice());
                    currentState = GameState.MainMenu;
                }

                break;

            case GameState.Running:
                startedGame = true;

                if (inputState.PauseGame)
                {
                    currentState = GameState.Paused;
                }

                if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed
#if !ZUNE
                    || Keyboard.GetState().IsKeyDown(Keys.W)
#endif
                    )
                {
                    gameScreen.RedPaddleDirection = PaddleDirection.Up;
                }
                else if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed
#if !ZUNE
                         || Keyboard.GetState().IsKeyDown(Keys.S)
#endif
                         )
                {
                    gameScreen.RedPaddleDirection = PaddleDirection.Down;
                }
                else
                {
                    gameScreen.RedPaddleDirection = PaddleDirection.Stop;
                }

                if (GamePad.GetState(PlayerIndex.Two).DPad.Up == ButtonState.Pressed
#if !ZUNE
                    || Keyboard.GetState().IsKeyDown(Keys.Up)
#endif
                    )
                {
                    gameScreen.BluePaddleDirection = PaddleDirection.Up;
                }
                else if (GamePad.GetState(PlayerIndex.Two).DPad.Down == ButtonState.Pressed
#if !ZUNE
                         || Keyboard.GetState().IsKeyDown(Keys.Down)
#endif
                         )
                {
                    gameScreen.BluePaddleDirection = PaddleDirection.Down;
                }
                else
                {
                    gameScreen.BluePaddleDirection = PaddleDirection.Stop;
                }

                gameScreen.NextPosition(gameTicksPerSecond);

                break;

            case GameState.GameOver:
                if (inputState.MenuCancel || inputState.MenuSelect)
                {
                    currentState = GameState.MainMenu;
                }
                break;

            case GameState.Paused:
                if (inputState.MenuSelect)
                {
                    currentState = GameState.Running;
                }

                if (inputState.MenuCancel)
                {
                    currentState = GameState.MainMenu;
                }

                break;

            case GameState.ExitScreen:
                if (inputState.MenuCancel)
                {
                    currentState = GameState.MainMenu;
                }

                if (
                    GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed
#if ZUNE
                    || inputState.MenuSelect
#endif
                    )
                {
                    this.Exit();
                }

                break;
            }

            base.Update(gameTime);
        }
Example #2
0
 public static void Save(StorageDevice storageDevice, PongConfig config)
 {
     config.Save(storageDevice);
 }