diff --git a/src/linea/CampagneEspace.java b/src/linea/CampagneEspace.java new file mode 100644 index 0000000..87c1917 --- /dev/null +++ b/src/linea/CampagneEspace.java @@ -0,0 +1,48 @@ +package linea; + +import javax.swing.Timer; + +public class CampagneEspace { + protected Jeu jeu; + + public CampagneEspace(Jeu j) { + this.jeu = j; + } + + public void lancerNiveauLune(int nivDifficulte) { + System.out.println("Lancement Espace - Difficulté : " + nivDifficulte); + + if(jeu.horloge != null) { + jeu.horloge.stop(); + } + jeu.horloge = new Timer(40, jeu); + + jeu.ecran.viderObjets(); + + // 1. Fond étoilé + FondEspace fond = new FondEspace(); + jeu.ecran.ajouterObjet(fond); + + // 2. Ligne de trajectoire + jeu.laligne = new Ligne(); + jeu.ecran.ajouterObjet(jeu.laligne); + + // 3. Cercle Espace avec physique Lunaire (niveau 1) + CercleEspace halo = new CercleEspace(0, 360, 1); + jeu.ecran.ajouterObjet(halo); + + // Liaisons contrôles + jeu.demiCercleAvant = halo; + jeu.demiCercleArriere = halo; + + // UI et lancement + jeu.ecran.setGameOver(false); + jeu.score = 0; + jeu.labScore.setText("

LUNE - score : 0

"); + + jeu.layout.show(jeu.conteneurPrincipal, "JEU"); + jeu.ecran.setFocusable(true); + jeu.ecran.requestFocusInWindow(); + jeu.horloge.start(); + } +} \ No newline at end of file diff --git a/src/linea/CercleEspace.java b/src/linea/CercleEspace.java new file mode 100644 index 0000000..99d03dd --- /dev/null +++ b/src/linea/CercleEspace.java @@ -0,0 +1,41 @@ +package linea; +import java.awt.*; +import java.awt.geom.Arc2D; + +public class CercleEspace extends Cercle { + + protected double gravite; + + public CercleEspace(double debutArc, double finArc, int niveauEspace) { + super(debutArc, finArc); + this.x = 400; + this.y = 200; + + if (niveauEspace == 1) { // LUNE + this.gravite = 1.62; + this.couleur = Color.WHITE; + } + } + + @Override + void Afficher(Graphics g) { + Graphics2D g2D = (Graphics2D) g; + + // Halo extérieur (lueur) + g2D.setStroke(new BasicStroke(12.0f)); + Color haloColor = new Color(this.couleur.getRed(), this.couleur.getGreen(), this.couleur.getBlue(), 60); + g2D.setColor(haloColor); + g2D.draw(new Arc2D.Double(x-rayon/2, y-rayon, rayon, rayon*2, debut, fin, Arc2D.OPEN)); + + // Cercle central brillant + g2D.setStroke(new BasicStroke(3.0f)); + g2D.setColor(this.couleur); + g2D.draw(new Arc2D.Double(x-rayon/2, y-rayon, rayon, rayon*2, debut, fin, Arc2D.OPEN)); + } + + @Override + void Animer() { + // On conserve la physique de base de Cercle (gravité/impulsion standard) + super.Animer(); + } +} diff --git a/src/linea/FondEspace.java b/src/linea/FondEspace.java new file mode 100644 index 0000000..eb68cec --- /dev/null +++ b/src/linea/FondEspace.java @@ -0,0 +1,39 @@ +package linea; + +import java.awt.Color; +import java.awt.Graphics; +import java.util.Random; + +public class FondEspace extends ObjetGraphique { + private int[] starX = new int[100]; + private int[] starY = new int[100]; + private Random rand = new Random(); + + public FondEspace() { + for (int i = 0; i < 100; i++) { + starX[i] = rand.nextInt(800); + starY[i] = rand.nextInt(600); + } + } + + @Override + void Afficher(Graphics g) { + // Espace profond + g.setColor(Color.BLACK); + g.fillRect(0, 0, 800, 600); + + // Étoiles + g.setColor(Color.WHITE); + for (int i = 0; i < 100; i++) { + g.fillOval(starX[i], starY[i], 2, 2); + } + } + + @Override + void Animer() { + for (int i = 0; i < 100; i++) { + starX[i] -= 2; // Défilement vers la gauche + if (starX[i] < 0) starX[i] = 800; + } + } +} \ No newline at end of file diff --git a/src/linea/Jeu.java b/src/linea/Jeu.java index a56692a..195c40a 100644 --- a/src/linea/Jeu.java +++ b/src/linea/Jeu.java @@ -92,6 +92,9 @@ public class Jeu implements KeyListener, ActionListener { if (idCampagneActive == 1) { CampagneAutoroute campagne = new CampagneAutoroute(this); campagne.lancerNiveau(numeroNiveau); + } else if (idCampagneActive == 2) { + CampagneEspace campagne = new CampagneEspace(this); + campagne.lancerNiveauLune(numeroNiveau); } else if (idCampagneActive == 3) { CampagneOcean campagne = new CampagneOcean(this);