title: Simple ping pong game in C#
body: <p><img src="https://i.stack.imgur.com/0PCfq.png" alt="Ping Pong"></p>
  
  <p>Hi, I'm making this game called "Ping Pong". I made an algo for the movement of the ball. Now, I want that <strong>whenever the ball touches or collides with the player (pictured above), it should bounce off</strong> just as it bounces when it touch the edges. Any suggestions??</p>
  
  <p>For ref. here's a snippet from my code till now...</p>
  
  <pre><code>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 &lt; 1)
                      dx = dx + 6;
  
                  if (x &gt;= 800 - ball1.Width)
                      dx = dx - 6;
  
                  if (y &lt; 0)
                      dy = dy + 6;
  
                  if (y &gt; 450 - ball1.Height)
                      dy = dy - 6;
  
                  if (x == -3 &amp;&amp; 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);
              } 
  </code></pre>