Merge branch 'main' of https://titi.koxi.nl/blodat/projet-dev
This commit is contained in:
79
src/Bonus.java
Normal file
79
src/Bonus.java
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
g.setColor(this.couleur);
|
||||||
|
g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
// On compte le temps uniquement si le bonus n'est pas déjà sur l'écran
|
||||||
|
if (!actif) {
|
||||||
|
compteurFrames++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TEMPS RÉDUIT POUR TESTER : 50 frames = 2 secondes (au lieu de 375)
|
||||||
|
if (compteurFrames >= 100 && !actif) {
|
||||||
|
actif = true;
|
||||||
|
x = 800;
|
||||||
|
|
||||||
|
double hauteurLigne = 300;
|
||||||
|
if (maLigne.dernierSegment != null) {
|
||||||
|
hauteurLigne = maLigne.dernierSegment.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
double decalage = (Math.random() * 80) - 40;
|
||||||
|
y = hauteurLigne + decalage;
|
||||||
|
|
||||||
|
// Ce message s'affichera dans ta console Eclipse/IntelliJ/VSCode
|
||||||
|
System.out.println("DEBUG : Le bonus apparait à Y = " + y);
|
||||||
|
|
||||||
|
compteurFrames = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actif) {
|
||||||
|
x -= 10;
|
||||||
|
|
||||||
|
// --- VÉRIFICATION DE LA COLLISION ---
|
||||||
|
double centreX = x + (taille / 2.0);
|
||||||
|
double centreY = y + (taille / 2.0);
|
||||||
|
double dx = centreX - monCercle.x;
|
||||||
|
double dy = centreY - monCercle.y;
|
||||||
|
double distance = Math.sqrt((dx * dx) + (dy * dy));
|
||||||
|
|
||||||
|
if (distance < monCercle.getRayon()) {
|
||||||
|
System.out.println("DEBUG : Bonus attrapé ! +1 Vie");
|
||||||
|
monJeu.vies += 1;
|
||||||
|
actif = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x + taille < 0) {
|
||||||
|
System.out.println("DEBUG : Bonus raté, il est sorti de l'écran");
|
||||||
|
actif = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,6 +109,9 @@ public class Jeu implements KeyListener, ActionListener, MouseListener {
|
|||||||
public void lancerPartie(String pseudoSaisi) {
|
public void lancerPartie(String pseudoSaisi) {
|
||||||
pseudo = pseudoSaisi;
|
pseudo = pseudoSaisi;
|
||||||
|
|
||||||
|
// C'est cette ligne qui donne vie au bonus !
|
||||||
|
ecran.ajouterObjet(new Bonus(lili, demiCercleAvant, this));
|
||||||
|
|
||||||
// A FAIRE : placer dans l'écran tous les objets graphiques nécessaires
|
// A FAIRE : placer dans l'écran tous les objets graphiques nécessaires
|
||||||
ecran.ajouterObjet(demiCercleArriere);
|
ecran.ajouterObjet(demiCercleArriere);
|
||||||
ecran.ajouterObjet(lili);
|
ecran.ajouterObjet(lili);
|
||||||
|
|||||||
Reference in New Issue
Block a user