XNA GameStudio 2.0
Adding Spin

We aren't very far now from making the game playable. At the moment, the way that the ball bounces off the bat doesn't give the players any real control over the direction of the ball - we need to find some way to fix that.

In bat and ball games, it is normal for the ball to bounce off a bat differently according to whereabouts it struck the bat. If the ball hits the bat near to an edge it should bounce back in that direction - if it hits the centre of the bat, it should bounce off pretty much straight.

This is a fairly complex thing to achieve and quite hard to explain. Some of it is worked out by trial and error. Return to the code you wrote to manage the bat/ball collisions and change it so that it looks like the following,

if (player1.BatRect.Contains(ball.BallRect))
{
   ball.velocity.X *= -1.0f;
   ball.velocity.Y = ((ball.position.Y - (player1.position.Y - ball.sprite.Height)) / (player1.sprite.Height + (2 * ball.sprite.Height)) * 10.0f) - 5.0f;
}
if (player2.BatRect.Contains(ball.BallRect))
{
   ball.velocity.X *= -1.0f;
   ball.velocity.Y = ((ball.position.Y - (player2.position.Y - ball.sprite.Height)) / (player2.sprite.Height + (2 * ball.sprite.Height)) * 10.0f) - 5.0f;
}

Test this and check that you can direct the ball a little. It doesn't matter if this isn't perfect as long as there is some sense of control for the players.

Adjustments

This is a good point in the development process to think about changing anything that doesn't work as well as we would like. You need to check that the game is possible to play - does the ball move too quick or too slow? Do the bats move quickly enough?

Make any changes that you think are necessary before moving on to the next section.