-fill campagne autoroute
This commit is contained in:
51
src/linea/CampagneAutoroute.java
Normal file
51
src/linea/CampagneAutoroute.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class CampagneAutoroute {
|
||||||
|
|
||||||
|
protected Jeu jeu; // Référence au jeu principal
|
||||||
|
|
||||||
|
public CampagneAutoroute(Jeu j) {
|
||||||
|
this.jeu = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lancerNiveau1() {
|
||||||
|
System.out.println("Lancement du niveau No Hesi...");
|
||||||
|
|
||||||
|
|
||||||
|
if(jeu.horloge != null) {
|
||||||
|
jeu.horloge.stop();
|
||||||
|
}
|
||||||
|
jeu.horloge = new Timer(40, jeu);
|
||||||
|
|
||||||
|
|
||||||
|
jeu.ecran.viderObjets();
|
||||||
|
|
||||||
|
|
||||||
|
FondAutoroute fond = new FondAutoroute();
|
||||||
|
jeu.ecran.ajouterObjet(fond);
|
||||||
|
|
||||||
|
jeu.laligne = new Ligne(); // La ligne
|
||||||
|
jeu.ecran.ajouterObjet(jeu.laligne);
|
||||||
|
|
||||||
|
Voiture maVoiture = new Voiture();
|
||||||
|
|
||||||
|
jeu.ecran.ajouterObjet(maVoiture);
|
||||||
|
|
||||||
|
jeu.demiCercleAvant = maVoiture;
|
||||||
|
jeu.demiCercleArriere = maVoiture;
|
||||||
|
|
||||||
|
|
||||||
|
jeu.ecran.setGameOver(false);
|
||||||
|
jeu.score = 0;
|
||||||
|
jeu.labScore.setText("<html><h3 style='color:white;'>score : 0</h3></html>");
|
||||||
|
|
||||||
|
|
||||||
|
jeu.layout.show(jeu.conteneurPrincipal, "JEU");
|
||||||
|
jeu.ecran.setFocusable(true);
|
||||||
|
jeu.ecran.requestFocusInWindow();
|
||||||
|
jeu.horloge.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/linea/FondAutoroute.java
Normal file
42
src/linea/FondAutoroute.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
public class FondAutoroute extends ObjetGraphique {
|
||||||
|
|
||||||
|
private double decalage = 0;
|
||||||
|
|
||||||
|
public FondAutoroute() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
// Ciel de nuit urbaine
|
||||||
|
g.setColor(new Color(20, 20, 45));
|
||||||
|
g.fillRect(0, 0, 800, 50);
|
||||||
|
|
||||||
|
// Asphalte de l'autoroute en bas
|
||||||
|
g.setColor(new Color(30, 30, 30));
|
||||||
|
g.fillRect(0, 50, 800, 500);
|
||||||
|
|
||||||
|
// Lignes de séparation de voie qui défilent
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
for(int i = 0; i < 900; i += 120) {
|
||||||
|
for(int j = 0; j < 500; j+=167) {
|
||||||
|
g.fillRect(i - (int)decalage, 117+j, 60, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.setColor(new Color(20, 20, 45));
|
||||||
|
g.fillRect(0, 550, 800, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
decalage += 5.0;
|
||||||
|
if (decalage >= 120) {
|
||||||
|
decalage = 0; // Boucle infinie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,7 +118,18 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
|
|
||||||
labScore.setText("<html><h3>score : " + score+"</h3></html>");
|
labScore.setText("<html><h3>score : " + score+"</h3></html>");
|
||||||
// Gestion collision simple
|
// Gestion collision simple
|
||||||
if (Math.abs(laligne.getHauteurLigneA(400) - demiCercleAvant.getY()) > 30) {
|
double hauteurLigne = laligne.getHauteurLigneA(400);
|
||||||
|
if (hauteurLigne != -1) {
|
||||||
|
// calcule de la distance entre le centre du cercle et la ligne
|
||||||
|
double distance = Math.abs(hauteurLigne - demiCercleAvant.getY());
|
||||||
|
|
||||||
|
// Si cette distance est strictement supérieure au rayon du bouclier,
|
||||||
|
// cela signifie que la ligne est sortie de la bulle !
|
||||||
|
if (distance > demiCercleAvant.getRayon()) {
|
||||||
|
gameOver();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Si on arrive au bout de la ligne
|
||||||
gameOver();
|
gameOver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ public class MenuCampagne extends JPanel {
|
|||||||
JButton btnRetour = creerBouton("RETOUR");
|
JButton btnRetour = creerBouton("RETOUR");
|
||||||
|
|
||||||
btnC1.addActionListener(e -> System.out.println("Lancement Campagne 1..."));
|
btnC1.addActionListener(e -> System.out.println("Lancement Campagne 1..."));
|
||||||
btnC2.addActionListener(e -> System.out.println("Lancement Campagne 2..."));
|
// Remplace le System.out.println par l'appel à ta nouvelle classe :
|
||||||
|
btnC2.addActionListener(e -> {
|
||||||
|
CampagneAutoroute campagne = new CampagneAutoroute(jeu);
|
||||||
|
campagne.lancerNiveau1();
|
||||||
|
});
|
||||||
|
|
||||||
btnRetour.addActionListener(e -> jeu.afficherMenuPrincipal());
|
btnRetour.addActionListener(e -> jeu.afficherMenuPrincipal());
|
||||||
|
|
||||||
|
|||||||
48
src/linea/Voiture.java
Normal file
48
src/linea/Voiture.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Arc2D;
|
||||||
|
|
||||||
|
public class Voiture extends Cercle { // Hérite de Cercle
|
||||||
|
|
||||||
|
// On définit les couleurs directement ici pour simplifier
|
||||||
|
private Color couleurArriere = Color.GRAY;
|
||||||
|
private Color couleurAvant = Color.GRAY;
|
||||||
|
|
||||||
|
public Voiture() {
|
||||||
|
super();
|
||||||
|
this.rayon = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
|
g2D.setStroke(new BasicStroke(5.0f));
|
||||||
|
|
||||||
|
// 1. DESSINER LE DEMI-CERCLE ARRIERE (Au fond)
|
||||||
|
g2D.setColor(couleurArriere);
|
||||||
|
// Utilisation de rayon*2 pour la largeur et hauteur (cercle parfait)
|
||||||
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, 180, Arc2D.OPEN));
|
||||||
|
|
||||||
|
// 2. DESSINER LA VOITURE (Au milieu)
|
||||||
|
g.setColor(new Color(150, 50, 200));
|
||||||
|
g.fillRect((int)x - 20, (int)y - 5, 40, 12);
|
||||||
|
|
||||||
|
g.setColor(Color.CYAN);
|
||||||
|
g.fillRect((int)x - 10, (int)y - 15, 20, 10);
|
||||||
|
|
||||||
|
g.setColor(Color.DARK_GRAY);
|
||||||
|
g.fillOval((int)x - 15, (int)y + 3, 10, 10);
|
||||||
|
g.fillOval((int)x + 5, (int)y + 3, 10, 10);
|
||||||
|
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
g.fillOval((int)x + 15, (int)y - 2, 6, 6);
|
||||||
|
|
||||||
|
// 3. DESSINER LE DEMI-CERCLE AVANT (Par-dessus)
|
||||||
|
g2D.setColor(couleurAvant);
|
||||||
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, -180, Arc2D.OPEN));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user