Hi, I am struggling with learning how to use colission detection in processing, and i would really appreciate some help, I have tried everything in my power to figure it out, but I just can’t do it. For a project in my class, I need to use this exact method to create a game and make it have a game over, however I am just testing it by doing a simple circle and square colission detection. The problem is im not sure how to detect corners, any help? P.S I apologize for the way my code is, I have been just testing stuff non stop.
float x,y;
final int RECT_SIZE = 50;
final int DIAM = 35;
boolean hit=false;
void setup(){
size(500,500);
noStroke();
x = random(0,width-RECT_SIZE);
y = random(0,height-RECT_SIZE);
}
void draw(){
background(#A1A2A1);
//rectangle
fill(#A21085);
rect(x,y,RECT_SIZE,RECT_SIZE);
pointOverlap(mouseX,mouseY,x,y,RECT_SIZE,RECT_SIZE);
//circle is green when it is NOT on the rectangle
fill(#00FF00);
if(hit){
fill(#FF0000);
}
ellipse(mouseX,mouseY,DIAM,DIAM);
// work on this
//hit = rectOverlap(x1,y1,x2,y2,size1,size2);
}
//and this
boolean pointOverlap(float x1,float y1, float x2, float y2, float size1, float size2){
boolean test = false;
if(x1+size1/2>=x2&&y1+size1/2==y2){
test=true;
print(test);
}
return test;
}
//and this
boolean rectOverlap(float x1,float y1, float x2, float y2, float size1,float size2){
boolean test = false;
return test;
}
//this makes the square move when you click the mouse
void mousePressed(){
x = random(0,width-RECT_SIZE);
y = random(0,height-RECT_SIZE);
}