Here you are (your help is much appreciated
class Runner{
PVector pos = new PVector();
Runner(float x,float y){
pos.x=x;
pos.y=y;
}
void show(){
fill(255,0,0);
stroke(0,0,255);
ellipse(pos.x,pos.y,size,size);
//b = loadImage("ball.png");
//image(b,pos.x-size/2,pos.y-size/2,size,size);
}
void gravity(){
if (pos.y != size/2+2 && pos.y>0) pos.y--;
else if (pos.y != -size/2-2 && pos.y<0) pos.y++;
}
void invert(){
pos.y*=-1;
}
}
class Obstacles{
PVector pos = new PVector();
PVector dim = new PVector();
Obstacles(float x, float h, float w){
pos.x=x;
pos.y=0;
dim.x=w;
dim.y=h;
}
void drawRect(){
stroke(0);
fill(0);
rect(pos.x,pos.y,dim.x,dim.y);
}
float sideInit(){
side = random(0,1);
if(side>0.5) return 1;
return -1;
}
}
Runner ball;
//PImage b;
Obstacles obj = new Obstacles(0,0,0);
int size=50;
float offx=0;
float side;
void setup(){
size(640,640);
translate(-offx,height/2);
//ball = new Runner(size/2+width/6.4,size/2);
ball = new Runner(size/2+width/6.4,-100);
side = obj.sideInit();
obj = new Obstacles(width,side*random(50,90),random(size/2,100));
background(255);
strokeWeight(4);
frameRate(120);
}
void draw(){
translate(-offx,height/2);
background(255);
obj.drawRect();
ball.gravity();
ball.show();
stroke(0);
line(0,0,width+offx,0);
ball.pos.x+=4;
offx+=4;
boolean hit = circleRect(ball.pos.x,ball.pos.y,size/2, obj.pos.x,obj.pos.y,obj.dim.x,obj.dim.y);
if (hit) noLoop();
if (obj.pos.x<offx) {side=obj.sideInit();obj = new Obstacles(width+offx,side*random(50,90),random(size/2,100));}
}
void mousePressed(){
ball.invert();
}
void keyPressed(){
if(keyCode==32) ball.pos.y = -200;
}
boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) {
float testX = cx;
float testY = cy;
if (cx < rx) testX = rx;
else if (cx > rx+rw) testX = rx+rw;
if (cy < ry) testY = ry;
else if (cy > ry+rh) testY = ry+rh;
float distX = cx-testX;
float distY = cy-testY;
float distance = sqrt( (distX*distX) + (distY*distY) );
if (distance <= radius) return true;
return false;
}