2026-03-16 15:43:35 +01:00
|
|
|
package linea;
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Graphics;
|
|
|
|
|
|
|
|
|
|
public class Bonus extends ObjetGraphique {
|
|
|
|
|
|
|
|
|
|
protected double taille = 10;
|
|
|
|
|
protected boolean actif = false;
|
|
|
|
|
protected int compteurFrames = 0;
|
2026-03-16 16:31:57 +01:00
|
|
|
protected boolean dejaCapture = false;
|
|
|
|
|
|
2026-03-16 15:43:35 +01:00
|
|
|
|
|
|
|
|
protected Ligne maLigne;
|
|
|
|
|
protected Cercle monCercle;
|
|
|
|
|
protected Jeu monJeu;
|
|
|
|
|
|
|
|
|
|
public Bonus(Ligne l, Cercle c, Jeu j) {
|
|
|
|
|
this.maLigne = l;
|
|
|
|
|
this.monCercle = c;
|
|
|
|
|
this.monJeu = j;
|
|
|
|
|
this.couleur = Color.RED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void Afficher(Graphics g) {
|
|
|
|
|
if (actif) {
|
2026-03-16 16:31:57 +01:00
|
|
|
if (dejaCapture) {
|
|
|
|
|
g.setColor(Color.ORANGE);
|
|
|
|
|
} else {
|
|
|
|
|
g.setColor(this.couleur);
|
|
|
|
|
}
|
2026-03-16 15:43:35 +01:00
|
|
|
g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void Animer() {
|
|
|
|
|
if (!actif) {
|
|
|
|
|
compteurFrames++;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 16:31:57 +01:00
|
|
|
if (compteurFrames >= 300 && !actif) {
|
|
|
|
|
|
2026-03-16 15:43:35 +01:00
|
|
|
actif = true;
|
2026-03-16 16:31:57 +01:00
|
|
|
dejaCapture = false;
|
|
|
|
|
|
2026-03-16 15:43:35 +01:00
|
|
|
x = 800;
|
|
|
|
|
|
|
|
|
|
double hauteurLigne = 300;
|
|
|
|
|
if (maLigne.dernierSegment != null) {
|
|
|
|
|
hauteurLigne = maLigne.dernierSegment.y;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 16:31:57 +01:00
|
|
|
if (Math.random() > 0.5) {
|
|
|
|
|
y = hauteurLigne - 80 - (Math.random() * 50);
|
|
|
|
|
} else {
|
|
|
|
|
y = hauteurLigne + 30 + (Math.random() * 20);
|
|
|
|
|
}
|
2026-03-16 15:43:35 +01:00
|
|
|
|
2026-03-16 16:31:57 +01:00
|
|
|
if (y < 20) y = 20;
|
|
|
|
|
if (y > 550) y = 550;
|
2026-03-16 15:43:35 +01:00
|
|
|
|
|
|
|
|
compteurFrames = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (actif) {
|
|
|
|
|
x -= 10;
|
|
|
|
|
|
2026-03-16 16:31:57 +01:00
|
|
|
|
|
|
|
|
|
2026-03-16 15:43:35 +01:00
|
|
|
double centreX = x + (taille / 2.0);
|
2026-03-16 16:31:57 +01:00
|
|
|
|
|
|
|
|
if (centreX <= monCercle.x && centreX > monCercle.x - 10) {
|
|
|
|
|
|
|
|
|
|
double hautCercle = monCercle.y - monCercle.getRayon();
|
|
|
|
|
double basCercle = monCercle.y + monCercle.getRayon();
|
|
|
|
|
|
|
|
|
|
if (y > hautCercle && (y + taille) < basCercle) {
|
|
|
|
|
|
|
|
|
|
if (!dejaCapture) {
|
|
|
|
|
monJeu.vies += 1;
|
|
|
|
|
dejaCapture = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-16 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x + taille < 0) {
|
|
|
|
|
actif = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|