title: Change Ball Direction after collision with another ball
body: <p>I need to change Ball Direction after collision with another ball or with a edge of the window.
  I managed to do something like that:</p>
  
  <pre><code>y += yMove;
  x += xMove;
  
  //if the ball moves to the right edge of the window, turn around. 
  if(x &gt; width - size)
  {   
      x = width - size;
      xMove *= -1;
      if (xMove &gt; 0) {
         xSpeed = xMove + (Math.random() * (1));
      }
      if (xMove &lt;= 0) {
         xSpeed = xMove - (Math.random() * (1));
      }
      if (yMove &gt; 0) {
         ySpeed = yMove + (Math.random() * (1));
      }
      if (yMove &lt;= 0) {
         ySpeed = yMove - (Math.random() * (1));
      }
  }
  </code></pre>
  
  <p>And same for another edges.</p>
  
  <p>I'm trying to use same method for changing direction of balls after they collide with each other, but it's just not working / it's weird. Can anyone help me?</p>