YAAAAAAAAAAAY :) Now time to introduce this to my main code.
CODE:
int ball = 20;
int ball2 = 20;
float xpos = 0;
float ypos = 230;
int xdirection = 1;
void setup(){
size(500,500);
smooth();
}
void draw(){
background(0);
xpos = xpos + xdirection;
if(xpos > 470){
xdirection = xdirection * - 1;
}
if(xpos < 0){
xdirection = xdirection * -1;
}
if(dist(ball,xpos,ball2,ypos) <15){
xdirection = xdirection * -1;
}
ellipse(xpos+ball, ypos+ball,ball,ball);
ellipse(ypos+ball2, xpos+ball2,ball2,ball2);
fill(255);
}
So now I have finally figured how to make them collide and reflect off each other. And now it turns out it was really simple :/ But now I understand it completley and ready to explore more in my code.