private void SetRandomDirection() { // Get a random angle pointing right from 55 to 125 degrees direction = Calc2D.GetRightPointingAngledPoint(rand.Next(55, 125)); if (rand.Next(2) == 1) { direction = -direction; } }
void Bounce(Sprite paddle) { Velocity *= 1.04f; // Calculate a new direction depending on where on the paddle the ball bounces float differenceToTargetCenter = paddle.BoundingBox.Center.Y - BoundingBox.Center.Y; direction = Calc2D.GetRightPointingAngledPoint((int)(90 + (differenceToTargetCenter * 1.3f))); // Set a new position to make sure we're outside the paddle if (paddle.BoundingBox.Center.X > BoundingBox.Center.X) { direction.X = -direction.X; position.X = paddle.BoundingBox.Left - texture.Width; } else { position.X = paddle.BoundingBox.Right; } }