Kreis kreis;
Rechteck rechteck;
Bricks bricks;
int x,y,r; //Kreis Position nd grösse
int x2,y2,l2,b2; // Rechteck grösse und Position
int vx,vy; // Kreis Geschwindigkeit
int vx2,vy2;// Rechteck Geschwindigkeit
color c,c2; //Farben Kreis&Rechteck
int x3,y3;
int l3,b3;
int a;
void setup(){
x=100; y=100; r=25;
x2=200; y2=450; l2=100; b2=20;
vx=2; vy=2; vx2=2; vy2=2;
; c2=100;
x3= 20; y3= 40;
l3=50; b3=20;
kreis = new Kreis(x,y,r,x2,y2,vx,vy,l2,b2,c2);
rechteck = new Rechteck(x,y,r,x2,y2,l2,b2,vx,vy,vx2,vy2,c2);
bricks = new Bricks(x3,y3,l3,b3,a,c);
size(500,500);
}
void draw(){
background(200);
kreis.zeichnen();
kreis.kolrand();
rechteck.keyPressed();
rechteck.zeichnen();
kreis.kolobj();
rechteck.kolrand();
}
class Kreis{
Rechteck rechteck;
int x,y,r;
int vx,vy;
color c;
int x2,y2,l2,b2;
Kreis(int x0, int y0, int r0, int x20, int y20, int vx0, int vy0, int l20, int b20, int c0){ // defintion varaibelne
x=x0; y=y0; r=r0;x2= x20; y2=y20;vx=vx0; vy=vy0; l2=l20 ;b2=b20;c=c0;
}
void zeichnen(){
fill(c);circle(x,y,r);
x=x-vx; y=y+vy;
}
//Kreis kollidiert mit Rändern
void kolrand(){
if( (x+r/2>=width) || (x-r/2<=0) ){ vx=-vx;}
if( (y-r/2<=0) ){ vy=-vy;}
}
void kolobj(){
//Kollision an den Objekten
if (y>=y2 && y<=y2+b2) { //Kreis ist über oder unter Rand
if(abs(x2-x-l2) <=r/2 || abs(x-x2) <=r/2){ vx=-vx;}
}
if (x>=x2 && x<=x2+l2) { //Kreis ist über oder unter Rand
if(abs(y-y2-b2) <=r/2 || abs(y-y2) <=r/2){ vy=-vy;
}
}
}
}
class Rechteck{
int x,y,r;
int vx,vy;
int x2,y2,l2,b2;
int vx2,vy2;
color c;
Rechteck(int x0, int y0, int r0,int x20, int y20, int l20,int b20, int vx0, int vy0, int vx20, int vy20, int c0){
x=x0; y=y0; r=r0;x2=x20; y2=y20; l2=l20; b2=b20; vx=vx0; vy=vy0;vx2= vx20; vy2=vy20; c=c0;
}
void zeichnen(){
fill(c);
rect(x2,y2,l2,b2);
}
void kolrand(){
if(x2<=0){
x2=x2+vx2;
}
if(x2+l2>=width){
x2=x2-vx2;
}
}
void keyPressed(){
if (keyCode == RIGHT) {x2=x2+vx2;}
if( keyCode == LEFT) {x2=x2-vx2;}
}
}