Hi, I'm making this game called "Ping Pong". I made an algo for the movement of the ball. Now, I want that whenever the ball touches or collides with the player (pictured above), it should bounce off just as it bounces when it touch the edges. Any suggestions??
For ref. here's a snippet from my code till now...
private void Ball()
{
int x = 1, y = 1, dx = 8, dy = 8;
System.Drawing.Point p;
while (true)
{
p = player.Location;
/*
here's where two or more if statements are required
*/
if (x < 1)
dx = dx + 6;
if (x >= 800 - ball1.Width)
dx = dx - 6;
if (y < 0)
dy = dy + 6;
if (y > 450 - ball1.Height)
dy = dy - 6;
if (x == -3 && y == -2)
dy = dy - 6;
x = x + dx;
y = y + dy;
ball1.Invoke
(
(MethodInvoker) delegate { ball1.Location = new System.Drawing.Point(x,y); }
);
Thread.Sleep(50);
}