示例#1
0
 private void BallBounces()
 {
     // ball bounce
     // within paddle bounds, change y direction
     if (ball.PosBottom() > paddle.PosTop() && ((ball.PosRight() >= paddle.PosLeft()) && (ball.PosRight() <= paddle.PosRight())))
     {
         ball.YSpeed *= -1;
     }
     // sets the hitbotton flag to be true, in which the GameOver function will be called in our game loop and game will exit
     if (ball.PosBottom() >= border.PosBottom())
     {
         hitBottom = true;
     }
     // top of screen, change y direction
     if (ball.PosTop() <= border.PosTop())
     {
         ball.YSpeed *= -1;
     }
     // left and right side of screen, change x direction
     if (ball.PosRight() >= border.PosRight() || ball.PosLeft() <= border.PosLeft())
     {
         ball.XSpeed *= -1;
     }
 }