Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }


            if (score.IsGameFinished())
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    score.Reset();
                    playerBar.ResetHorizontalMovementSpeed();
                    cpuBar.ResetHorizontalMovementSpeed();
                }
                return;
            }

            var keyboardState = Keyboard.GetState();
            var gamePadState  = GamePad.GetState(PlayerIndex.One);

            if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed)
            {
                playerBar.MoveUp();
            }

            if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed)
            {
                playerBar.MoveDown();
            }

            if (ballOutManager.IsBallOut())
            {
                ballOutManager.ResetBallAfterLatency();
                ballOutManager.GetBall().ResetHorizontalMovement();
                playerBar.ResetHorizontalMovementSpeed();
                cpuBar.ResetHorizontalMovementSpeed();
            }
            else
            {
                ballOutManager.Move();
                ballOutManager.GetBall().CheckHit(playerBar, cpuBar);
                cpuController.UpdatePosition();
            }
            base.Update(gameTime);
        }