#### codebeginnerg

##### Member
I have a problem with my code where the ball doesn't accurately detect the collision of the paddle on all point it deflect the ball at a certain area, but not all. Here is the paddle dimensions from paddle class:
x= 550
y= 170
width = 15;
height = 90;

C#:
`````` class ball
{
int x = 35; // initial x position of the ball
int y = 190; // initial y position of the ball
int dx = 20; // position increment for the ball on the x axis
int dy = 20; // position increment for the ball on the y axis
int xBall = 40;// width of the ball on the x axis
int yBall = 40;// width of the ball on the y axis
court c = new court();
public ball()
{
}

public void drawBall(Graphics b)
{
b.FillEllipse(Brushes.Green, x, y, xBall, yBall);
}
public void MoveBall()
{
int newBall_x = x + dx;
int newBall_y = y + dy;

// Bounce the ball if it has collided with a wall
if ((newBall_x < 30) || (newBall_x > 570)) dx = -dx;
if ((newBall_y < 50) || (newBall_y > 320)) dy = -dy;

// Bounce the ball if it has collided with the paddle
if (((newBall_x + xBall > p.paddle_x) && (newBall_x + xBall < (p.paddle_x +

{
dx = -dx;
}
x = x + dx;
y = y + dy;

}
}`````` Replies
4
Views
253
Replies
23
Views
2K
Replies
5
Views
797
Replies
15
Views
3K
Replies
10
Views
1K