Hi everyone I need a confirmation or a hand for a game: I am working with colored buttons and I need to understand if when I step on with the mouse they are selected and then transported within my sketch.
Can anyone tell me if how I did it could be correct?
float posOriginaleX;
float posOriginaleY;
color verde_color = (#12E300);
color viola_color = (#E200E3);
color arancio_color = (#E38100);
Bottone Bottone_verde;
Bottone Bottone_viola;
Bottone Bottone_arancio;
void setup() {
size(600, 600);
posOriginaleX = 160;
posOriginaleY = 20;
Bottone_verde = new Bottone(posOriginaleX, posOriginaleY, 2, 0, 255, color (0, 255, 0));
Bottone_viola = new Bottone(posOriginaleX, posOriginaleY, 1, 0, 255, color(255, 0, 255));
Bottone_arancio = new Bottone(posOriginaleX, posOriginaleY, 3, 0, 255, color(255, 117, 20));
}
void draw() {
background(0);
Bottone_verde.display();
Bottone_verde.update();
Bottone_viola.display();
Bottone_viola.update();
Bottone_arancio.display();
Bottone_arancio.update();
}
void mouseDragged() {
if (mouseButton == LEFT) {
}
}
class Bottone {
float posOriginaleX, posOriginaleY;
float posX, posY;
int size, min, max;
color c;
//Bottone Bottone;
Bottone(float xPosOrigin, float yPosOrigin, float xpos, float ypos, int s, color col) {
posOriginaleX = xPosOrigin;
posOriginaleY = yPosOrigin;
posX = xpos;
posY = ypos;
size = s;
c = col;
}
void display() {
noStroke();
fill(verde_color);
rect (posOriginaleX, posOriginaleY, 80, 80);
fill(viola_color);
rect (posOriginaleX+100, posOriginaleY, 80, 80);
fill(c);
rect (posOriginaleX+200, posOriginaleY, 80, 80);
}
void update() {
isInside();
}
boolean isInside() {
if (mouseX >= posOriginaleX && mouseX <= posOriginaleX && mouseY >= posOriginaleY && mouseY <= posOriginaleY) return true;
else return false;
}
}
Thanks