You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.5 KiB

class Pion extends Position {
int margin = 45; // marge au bord de l'écran
boolean lazored, animated = false;
int timer;
float savedRadius;
color bgColorHover;
Pion(int id) {
super(id);
this.bgColor = C_RED;
this.bgColorHover = C_YELLOW;
this.textColor = color(0, 0, 0);
this.posX = floor((displayWidth-margin*2)/nombreEquipes)*id+radius/2+margin;
this.posY = displayHeight-46;
this.radius = 30;
}
void draw() {
fireLazors(this);
color bgColor = this.getBgColor();
color textColor = this.getTextColor();
stroke(bgColor);
strokeWeight(0.5);
fill(bgColor);
float radius = this.radius;
circle(this.posX,this.posY,radius);
fill(textColor);
float textSize = radius/3*2;
textSize(textSize);
textFont(quicksandFont, textSize);
float pos_x = this.id<9? this.posX-radius/5: this.posX-radius/3;
text(this.id+1, pos_x, this.posY+radius/5+1);
}
color getBgColor() {
if (this.animated && this.lazored) return color(random(200, 255), random(0, 100), random(0, 100));
if (((frameCount-id) % 10)==0) return C_WHITE;
return this.dragged? C_YELLOW: this.hovered? this.bgColorHover: this.bgColor;
}
color getTextColor() {
return this.dragged? C_BLACK: this.hovered? this.textColor: this.textColor;
}
void hoverStop() {
this.hovered = false;
this.lazored = false;
}
void fireLazors(Pion p) {
// aucune interaction
if (!this.lazored && !this.animated) return;
//// début de l'animation
if (this.lazored && !this.animated) {
this.animated = true;
this.timer = millis();
this.savedRadius = this.radius;
}
// boucle d'animation
if (this.lazored && this.animated) {
if(this.radius<=100) {
this.radius += (millis()-this.timer)*0.0015;
}
}
// arrêt de l'animation
if (!this.lazored && this.animated) {
if(this.radius>=this.savedRadius) {
this.radius -= (millis()-this.timer)*0.003;
if (this.radius<=this.savedRadius) {
this.radius = this.savedRadius;
this.savedRadius = 0;
this.timer = millis();
this.animated = false;
this.lazored = false;
}
}
}
if (!this.lazored) return;
PVector target = new PVector(p.posX, p.posY);
//LAZOR(new PVector(245, 158), target);
//LAZOR(new PVector(displayWidth-245, 158), target);
LAZOR(new PVector(mouseX, mouseY), target);
}
}