hier diese Klasse beinhaltet die Collision Detection für zwei Rectangle Objekte, vllt. hilft dir das schon
falls du mal Circle - Rectangle brauchst einfach melden
Rectangle a;
Rectangle b;
void setup() {
size(600, 600);
a = new Rectangle(200, 100, 70, 120);
b = new Rectangle(100, 100, 50, 50);
}
void draw() {
background(100);
b.x = mouseX;
b.y = mouseY;
if (a.checkCollision(b)) {
a.col = color(255,100,100);
}else{
a.col = color(100,100,100);
}
a.drawRectangle();
b.drawRectangle();
}
private class Rectangle {
private float x, y, w, h;
private color col;
private Rectangle(float x, float y, float w, float h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
private void drawRectangle() {
rectMode(CORNER);
fill(col);
rect(x, y, w, h);
}
private boolean checkCollision(Rectangle b) {
return (this.x+this.w)>b.x && (this.x<(b.x+b.w)) && (this.y+this.h)>b.y && (this.y<(b.y+b.h));
}
}