I made this code, so that 2 squares passed by parameter collide. I try to make the collision based on the attributes of the squares
public boolean VerificarColisionCuadradoCuadrado(Cuadrado obj1, Cuadrado obj2) {
if (obj1.x + obj1.w <= obj2.x) {
return false;
}
if (obj1.y + obj1.h <= obj2.y) {
return false;
}
if (obj1.x > obj2.x + obj2.w) {
return false;
}
if (obj1.y > obj2.y + obj2.h) {
return false;
}
return true;
}
being square:
public class Cuadrado {
public int w, h;
public int x;
public int y;
public int color;
public void dibujarCuadrado(Graphics g, int posX, int posY, int base, int altura,int color) {
Line.drawline(g, posX, posY, base + posX, posY, color);
Line.drawline(g, base + posX, posY, base + posX, altura + posY,color);
Line.drawline(g, base + posX, altura + posY, posX, altura + posY,color);
Line.drawline(g, posX, altura + posY, posX, posY, color);
this.w=base;
this.h=altura;
this.x=posX;
this.y=posY;
this.color=color;
}
I can not find the error, they do not collide
the error I think is in the function
CheckColisionCuadradoCuadrado