change: bonus regroupé en une seule classe mere

classe objetcolldectile qui regroupe tout
This commit is contained in:
2026-03-27 19:17:03 +01:00
parent d69b806001
commit 16787a4113
5 changed files with 128 additions and 187 deletions

Binary file not shown.

View File

@@ -4,77 +4,33 @@ import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.util.List; import java.util.List;
public class Bonus extends ObjetGraphique { public class Bonus extends ObjetCollectible {
protected double taille = 10;
protected boolean actif = false;
protected int compteurFrames = 0;
protected boolean dejaCapture = false;
protected Ligne maLigne;
protected List<Joueur> joueurs;
protected Jeu monJeu;
public Bonus(Ligne l, List<Joueur> joueurs, Jeu j) { public Bonus(Ligne l, List<Joueur> joueurs, Jeu j) {
this.maLigne = l; super(l, joueurs, j);
this.joueurs = joueurs; this.taille = 10;
this.monJeu = j;
this.couleur = Color.GREEN; this.couleur = Color.GREEN;
} }
@Override protected int getSeuilActivation() { return 220; }
@Override protected Color getCouleurCapture() { return Color.BLUE; }
@Override @Override
void Afficher(Graphics g) { protected double calculerY(double hauteurLigne) {
if (actif) { if (Math.random() > 0.5) return hauteurLigne - 10 - (Math.random() * 50);
g.setColor(dejaCapture ? Color.BLUE : this.couleur); else return hauteurLigne + 10 + (Math.random() * 50);
}
@Override
protected void appliquerEffet(Joueur joueur) {
if (!monJeu.cheatMode) joueur.ajouterVie();
}
@Override
protected void dessiner(Graphics g) {
g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); 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;
}
}
}
} }

View File

@@ -4,77 +4,32 @@ import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.util.List; import java.util.List;
public class BonusTaille extends ObjetGraphique { public class BonusTaille extends ObjetCollectible {
protected double taille = 12;
protected boolean actif = false;
protected int compteurFrames = 200;
protected boolean dejaCapture = false;
protected Ligne maLigne;
protected List<Joueur> joueurs;
protected Jeu monJeu;
public BonusTaille(Ligne l, List<Joueur> joueurs, Jeu j) { public BonusTaille(Ligne l, List<Joueur> joueurs, Jeu j) {
this.maLigne = l; super(l, joueurs, j);
this.joueurs = joueurs; this.taille = 12;
this.monJeu = j;
this.couleur = Color.CYAN; this.couleur = Color.CYAN;
this.compteurFrames = 200; // démarre déjà à 200 pour apparaître plus tôt
}
@Override protected int getSeuilActivation() { return 320; }
@Override protected Color getCouleurCapture() { return new Color(255, 255, 255, 100); }
@Override
protected double calculerY(double hauteurLigne) {
if (Math.random() > 0.5) return hauteurLigne - 8 - (Math.random() * 45);
else return hauteurLigne + 8 + (Math.random() * 45);
} }
@Override @Override
void Afficher(Graphics g) { protected void appliquerEffet(Joueur joueur) {
if (actif) { joueur.activerBonusTaille();
g.setColor(dejaCapture ? new Color(255, 255, 255, 100) : this.couleur); }
@Override
protected void dessiner(Graphics g) {
g.fillOval((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); 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;
}
}
}
}

View File

@@ -4,77 +4,32 @@ import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.util.List; import java.util.List;
public class Malus extends ObjetGraphique { public class Malus extends ObjetCollectible {
protected double taille = 10;
protected boolean actif = false;
protected int compteurFrames = 0;
protected boolean dejaCapture = false;
protected Ligne maLigne;
protected List<Joueur> joueurs;
protected Jeu monJeu;
public Malus(Ligne l, List<Joueur> joueurs, Jeu j) { public Malus(Ligne l, List<Joueur> joueurs, Jeu j) {
this.maLigne = l; super(l, joueurs, j);
this.joueurs = joueurs; this.taille = 10;
this.monJeu = j;
this.couleur = Color.RED; this.couleur = Color.RED;
} }
@Override protected int getSeuilActivation() { return 250; }
@Override protected Color getCouleurCapture() { return Color.BLACK; }
@Override @Override
void Afficher(Graphics g) { protected double calculerY(double hauteurLigne) {
if (actif) { if (Math.random() > 0.5) return hauteurLigne - 75 - (Math.random() * 30);
g.setColor(dejaCapture ? Color.BLACK : this.couleur); else return hauteurLigne + 75 + (Math.random() * 30);
}
@Override
protected void appliquerEffet(Joueur joueur) {
if (!monJeu.cheatMode && !joueur.estInvincible()) joueur.retirerVie();
}
@Override
protected void dessiner(Graphics g) {
g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille); g.fillRect((int)Math.round(x), (int)Math.round(y), (int)taille, (int)taille);
} }
} }
@Override
void Animer() {
if (!actif) {
compteurFrames++;
}
if (compteurFrames >= 250 && !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 - 75 - (Math.random() * 30);
} else {
y = hauteurLigne + 75 + (Math.random() * 30);
}
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.estInvincible()) joueur.retirerVie();
dejaCapture = true;
break;
}
}
}
if (x + taille < 0) {
actif = false;
}
}
}
}

75
src/ObjetCollectible.java Normal file
View File

@@ -0,0 +1,75 @@
package linea;
import java.awt.Color;
import java.awt.Graphics;
import java.util.List;
public abstract class ObjetCollectible extends ObjetGraphique {
protected double taille;
protected boolean actif = false;
protected int compteurFrames = 0;
protected boolean dejaCapture = false;
protected Ligne maLigne;
protected List<Joueur> joueurs;
protected Jeu monJeu;
public ObjetCollectible(Ligne l, List<Joueur> joueurs, Jeu j) {
this.maLigne = l;
this.joueurs = joueurs;
this.monJeu = j;
}
protected abstract int getSeuilActivation();
protected abstract double calculerY(double hauteurLigne);
protected abstract void appliquerEffet(Joueur joueur);
protected abstract Color getCouleurCapture();
protected abstract void dessiner(Graphics g);
@Override
void Afficher(Graphics g) {
if (actif) {
g.setColor(dejaCapture ? getCouleurCapture() : this.couleur);
dessiner(g);
}
}
@Override
void Animer() {
if (!actif) compteurFrames++;
if (compteurFrames >= getSeuilActivation() && !actif) {
actif = true;
dejaCapture = false;
x = 800;
double hauteurLigne = 300;
if (maLigne.dernierSegment != null)
hauteurLigne = maLigne.dernierSegment.y;
y = calculerY(hauteurLigne);
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)) {
appliquerEffet(joueur);
dejaCapture = true;
break;
}
}
}
if (x + taille < 0) actif = false;
}
}
}