package linea; import java.awt.Color; import java.awt.Graphics; import java.util.List; public class BonusTaille extends ObjetGraphique { protected double taille = 12; protected boolean actif = false; protected int compteurFrames = 200; protected boolean dejaCapture = false; protected Ligne maLigne; protected List joueurs; protected Jeu monJeu; public BonusTaille(Ligne l, List joueurs, Jeu j) { this.maLigne = l; this.joueurs = joueurs; this.monJeu = j; this.couleur = Color.CYAN; } @Override void Afficher(Graphics g) { if (actif) { g.setColor(dejaCapture ? new Color(255, 255, 255, 100) : this.couleur); g.fillOval((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); } } @Override void Animer() { if (!actif) { compteurFrames++; } if (compteurFrames >= 320 && !actif) { actif = true; dejaCapture = false; x = 800; double hauteurLigne = 300; if (maLigne.dernierSegment != null) { hauteurLigne = maLigne.dernierSegment.y; } if (Math.random() > 0.5) { y = hauteurLigne - 8 - (Math.random() * 45); } else { y = hauteurLigne + 8 + (Math.random() * 45); } if (y < 20) y = 20; if (y > 550) y = 550; compteurFrames = 0; } if (actif) { double vitesseLigne = monJeu.gestionnaireNiveau.getVitesseScroll(); x -= vitesseLigne; if (!dejaCapture) { for (Joueur joueur : joueurs) { if (joueur.verifierCollisionCollectible(x, y, taille, vitesseLigne)) { joueur.activerBonusTaille(); dejaCapture = true; break; } } } if (x + taille < 0) { actif = false; } } } }