示例#1
0
 public override void UpdatePosition(Ball ball)
 {
     if (ball.GetDirection() > 1.5 * Math.PI || ball.GetDirection() < 0.5 * Math.PI)
     {
         if (ball.GetPosition().Y - 5 > GetPosition().Y + GetSize().Height / 2)
         {
             MoveDown();
         }
         else if (ball.GetPosition().Y == GetPosition().Y + GetSize().Height / 2)
         {
         }
         else if (ball.GetPosition().Y + 5 < GetPosition().Y + GetSize().Height / 2)
         {
             MoveUp();
         }
     }
     base.UpdatePosition(ball);
 }
示例#2
0
        private void UpdateCPUPaddle()
        {
            double moveDir = ball.GetPosition().x - cpuPaddle.GetRect().X;

            if (Math.Abs(moveDir) < 1)
            {
                return;
            }
            moveDir /= Math.Abs(moveDir);

            double speed = cpuSpeed;

            if (ball.GetDirection().y > 0)
            {
                speed = cpuSpeed / 3.0;
            }

            cpuPaddle.Move(moveDir * speed);
        }