Beispiel #1
0
        public void Update(KeyboardState kstate, GameTime gameTime)
        {
            if (kstate.IsKeyDown(Keys.Escape))
            {
                if (gameState == EGameState.Game)
                {
                    gameState = EGameState.GamePause;
                    game.gameProcess.Pause();
                }
            }
            switch (gameState)
            {
            case EGameState.MainMenu:
                mainMenu.Update(kstate, gameTime);
                break;

            case EGameState.Game:
                game.gameProcess.Run();
                interfaceGame.Update(kstate, gameTime);
                break;

            case EGameState.GamePause:
                menuPause.Update(kstate, gameTime);
                break;

            case EGameState.Exit:
                game.Exit();
                break;

            default:
                break;
            }
        }
        public void Update()
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                game.Exit();
            }

            // Keyboard controls
            KeyboardState keyboardsState = Keyboard.GetState();

            //Move mouse along with the player
            if (keyboardsState.GetPressedKeys().Length != 0)
            {
                //Movement
                if (keyboardsState.IsKeyDown(Keys.Left))
                {
                    game.Player.MoveOnXAxis(-game.Player.Speed);
                }
                else if (keyboardsState.IsKeyDown(Keys.Right))
                {
                    game.Player.MoveOnXAxis(game.Player.Speed);
                }

                Mouse.SetPosition((int)game.Player.Position.X,
                                  (int)game.Player.Position.Y);


                //Ball launch
                if (keyboardsState.IsKeyDown(Keys.Space) &&
                    !game.Ball.Launched)
                {
                    game.Ball.Launch();
                }
            }

            //Mouse controls
            MouseState mouseState = Mouse.GetState();

            if (mouseState.X != prevMouseState.X ||
                mouseState.Y != prevMouseState.Y)
            {
                game.Player.SetPos(mouseState.X, game.Player.Position.Y);
                prevMouseState = mouseState;
            }

            if (mouseState.LeftButton == ButtonState.Pressed &&
                !game.Ball.Launched)
            {
                game.Ball.Launch();
            }
        }
Beispiel #3
0
        /** Shows the game over dialog */
        public void LoadDialog(String Message)
        {
            DialogResult dialogResult = MessageBox.Show(
                "Play Again?",
                Message,
                MessageBoxButtons.YesNo
                );

            if (dialogResult == DialogResult.Yes)
            {
                game.Restart();
            }
            else if (dialogResult == DialogResult.No)
            {
                game.Exit();
            }
        }