package linea; import java.awt.Color; import java.awt.Graphics; import java.util.List; public class Bonus extends ObjetGraphique { protected double taille = 10; protected boolean actif = false; protected int compteurFrames = 0; protected boolean dejaCapture = false; protected Ligne maLigne; protected List joueurs; protected Jeu monJeu; public Bonus(Ligne l, List joueurs, Jeu j) { this.maLigne = l; this.joueurs = joueurs; this.monJeu = j; this.couleur = Color.GREEN; } @Override void Afficher(Graphics g) { if (actif) { g.setColor(dejaCapture ? Color.BLUE : this.couleur); g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); } } @Override void Animer() { if (!actif) { compteurFrames++; } if (compteurFrames >= 220 && !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 - 10 - (Math.random() * 50); } else { y = hauteurLigne + 10 + (Math.random() * 50); } 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)) { if (!monJeu.cheatMode) joueur.ajouterVie(); dejaCapture = true; break; } } } if (x + taille < 0) { actif = false; } } } }