Ajout de malus, ( mm logique que bonus )
perd 1 vie par malus, il faut l'éviter
This commit is contained in:
@@ -19,14 +19,14 @@ public class Bonus extends ObjetGraphique {
|
|||||||
this.maLigne = l;
|
this.maLigne = l;
|
||||||
this.monCercle = c;
|
this.monCercle = c;
|
||||||
this.monJeu = j;
|
this.monJeu = j;
|
||||||
this.couleur = Color.RED;
|
this.couleur = Color.GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void Afficher(Graphics g) {
|
void Afficher(Graphics g) {
|
||||||
if (actif) {
|
if (actif) {
|
||||||
if (dejaCapture) {
|
if (dejaCapture) {
|
||||||
g.setColor(Color.ORANGE);
|
g.setColor(Color.BLUE);
|
||||||
} else {
|
} else {
|
||||||
g.setColor(this.couleur);
|
g.setColor(this.couleur);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ public class Jeu implements KeyListener, ActionListener, MouseListener {
|
|||||||
|
|
||||||
// C'est cette ligne qui donne vie au bonus !
|
// C'est cette ligne qui donne vie au bonus !
|
||||||
ecran.ajouterObjet(new Bonus(lili, demiCercleAvant, this));
|
ecran.ajouterObjet(new Bonus(lili, demiCercleAvant, this));
|
||||||
|
ecran.ajouterObjet(new Malus(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);
|
||||||
|
|||||||
91
src/Malus.java
Normal file
91
src/Malus.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
public class Malus extends ObjetGraphique {
|
||||||
|
|
||||||
|
protected double taille = 10;
|
||||||
|
protected boolean actif = false;
|
||||||
|
protected int compteurFrames = 0;
|
||||||
|
protected boolean dejaCapture = false;
|
||||||
|
|
||||||
|
protected Ligne maLigne;
|
||||||
|
protected Cercle monCercle;
|
||||||
|
protected Jeu monJeu;
|
||||||
|
|
||||||
|
public Malus(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) {
|
||||||
|
if (dejaCapture) {
|
||||||
|
g.setColor(Color.black);
|
||||||
|
} else {
|
||||||
|
g.setColor(this.couleur);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
double centreX = x + (taille / 2.0);
|
||||||
|
|
||||||
|
if (centreX <= monCercle.x && centreX > monCercle.x - vitesseLigne) {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x + taille < 0) {
|
||||||
|
actif = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user