Exemple #1
0
        private void checkInput()
        {
            KeyboardState newState = Keyboard.GetState();

            oldState = newState;
            if (newState.IsKeyDown(Keys.Right))
            {
                if (!oldState.IsKeyDown(Keys.Right))
                {
                    paddle.MoveRight();
                    counter = 0;
                }
                else
                {
                    counter++;
                    if (counter > threshold)
                    {
                        paddle.MoveRight();
                    }
                }
            }
            if (newState.IsKeyDown(Keys.Left))
            {
                if (!oldState.IsKeyDown(Keys.Left))
                {
                    paddle.MoveLeft();
                    counter = 0;
                }
                else
                {
                    counter++;
                    if (counter > threshold)
                    {
                        paddle.MoveLeft();
                    }
                }
            }
            if (newState.IsKeyDown(Keys.Space))
            {
                if (!oldState.IsKeyDown(Keys.Space))
                {
                    paddle.autoMove();
                    counter = 0;
                }
                else
                {
                    counter++;
                    if (counter > threshold)
                    {
                        paddle.autoMove();
                    }
                }
            }
            oldState = newState;
        }
Exemple #2
0
 private void checkInput()
 {
     if (!isCPU)
     {
         KeyboardState newState = Keyboard.GetState();
         oldState = newState;
         if (newState.IsKeyDown(Keys.Up))
         {
             if (!oldState.IsKeyDown(Keys.Up))
             {
                 paddle.MoveUp();
                 counter = 0;
             }
             else
             {
                 counter++;
                 if (counter > threshold)
                 {
                     paddle.MoveUp();
                 }
             }
         }
         if (newState.IsKeyDown(Keys.Down))
         {
             if (!oldState.IsKeyDown(Keys.Down))
             {
                 paddle.MoveDown();
                 counter = 0;
             }
             else
             {
                 counter++;
                 if (counter > threshold)
                 {
                     paddle.MoveDown();
                 }
             }
         }
         if (newState.IsKeyDown(Keys.Space))
         {
             if (!oldState.IsKeyDown(Keys.Space))
             {
                 paddle.autoMove();
                 counter = 0;
             }
             else
             {
                 counter++;
             }
         }
         oldState = newState;
     }
 }