private void CheckBallCollision(AssetBase2D paddle) { var ball = this; if (ball.BoundingBox.Intersects(paddle.BoundingBox)) { //soundManager.Play("ping"); ball.Bounce(paddle); } }
public void Bounce(AssetBase2D 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; } }