Hello, I am trying to create a game. i have a class that draw triangles and i select them through a circle that is inside. The problem is when I have several figures, the circles overlap and I cannot select them one by one.
I want to know if there is a way to pass one figure over another and not “pick it up”
this is my code
Triangle triangle1;
Triangle triangle2;
Triangle triangle3;
void setup() {
fullScreen();
noStroke();
fill(0);
triangle1 = new Triangle(color(238, 241, 42), width/4, height/4, 1);
triangle2 = new Triangle(color(93, 241, 42), width/2, height/2, 2);
triangle3= new Triangle(color(152, 50, 138), 100,height/2, sqrt(2));
}
void draw() {
background(54,54,54);
triangle1.display();
triangle2.display();
triangle3.display();
}
class Triangle {
color c;
float xpos;
float ypos;
float escala;
float radius=25;
float angulo;
float l= 200;
float l4=l/4;
float l8=l/8;
Triangle(color tempc, float tempXpos, float tempYpos, float temp_e) {
c=tempc;
xpos= tempXpos;
ypos= tempYpos;
escala = temp_e;
radius=radius*escala;
l4=l4*escala;
l8=l8*escala;
}
void display() {
if (overcircle(mouseX, mouseY, xpos, ypos, radius)) {
fill(255, 150, 0);
} else fill(c);
dibujar();
if (select(xpos, ypos)) {
xpos=mouseX;
ypos=mouseY;
}
}
void dibujar() {
push();
noStroke();
figura();
stroke(0);
ellipse(xpos, ypos, radius, radius);
pop();
}
void figura(){
triangle(xpos, ypos-l8, xpos+l4, ypos+l8, xpos-l4, ypos+l8);
}
// POINT/CIRCLE
boolean overcircle(float px, float py, float cx, float cy, float r) {
float distX = px - cx;
float distY = py - cy;
float distance = sqrt( (distX*distX) + (distY*distY) );
if (distance <= r) {
return true;
}
return false;
}
boolean select(float cx, float cy) {
if (mousePressed && overcircle(mouseX, mouseY, cx, cy, radius)) return true;
else return false;
}
}