package linea; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; public class BouleBonus extends ObjetGraphique { private double rayon = 15; private double vitesse = 5.0; private boolean estVerte; // true = bonus (niveau +1), false = malus (niveau -1) private int frameCounter = 0; public BouleBonus(double x, double y, boolean estVerte) { this.x = x; this.y = y; this.estVerte = estVerte; if (estVerte) { this.couleur = new Color(0.0f, 0.8f, 0.0f); // Vert } else { this.couleur = new Color(0.8f, 0.0f, 0.0f); // Rouge } } public double getRayon() { return rayon; } public boolean isVerte() { return estVerte; } @Override void Afficher(Graphics g) { Graphics2D g2D = (Graphics2D) g; // Effet de pulsation (le rayon augmente/diminue) double rayonAffiche = rayon + Math.sin(frameCounter * 0.1) * 3; // Dessiner le cercle rempli g2D.setColor(couleur); g2D.fillOval((int)(x - rayonAffiche/2), (int)(y - rayonAffiche), (int)rayonAffiche, (int)rayonAffiche); // Contour g2D.setStroke(new BasicStroke(2.0f)); g2D.setColor(estVerte ? new Color(0.0f, 1.0f, 0.0f) : new Color(1.0f, 0.0f, 0.0f)); g2D.drawOval((int)(x - rayonAffiche/2), (int)(y - rayonAffiche), (int)rayonAffiche, (int)rayonAffiche); frameCounter++; } @Override void Animer() { // Déplacement vers la gauche (même vitesse que la ligne) x -= vitesse; } // Vérifier collision avec le cercle public boolean collisionAvec(Cercle c) { double cx = c.getX(); double cy = c.getY(); double cRayon = c.getRayon(); double dist = Math.hypot(cx - x, cy - y); return dist <= (rayon + cRayon); } public void setVitesse(double vitesse) { this.vitesse = vitesse; } }