class Pion extends Position {
  int margin = 45; // marge au bord de l'écran
  boolean lazored, animated = false;
  int timer;
  float savedRadius;
  
  Pion(int id) {
    super(id);
    this.bgColor = color(0, 0, 0);
    this.textColor = color(255, 255, 255);
    this.posX = floor((displayWidth-margin*2)/nombreEquipes)*id+radius/2+margin;
    this.posY = displayHeight-28;
    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(50, 150), random(50, 150));
    return this.dragged? color(177, 255, 51): this.hovered? this.textColor: this.bgColor;
  }
  
  color getTextColor() {
    return this.dragged? color(0): this.hovered? this.bgColor: 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);
  }
}
