diff --git a/src/linea/Bonus.java b/src/linea/Bonus.java new file mode 100644 index 0000000..428db74 --- /dev/null +++ b/src/linea/Bonus.java @@ -0,0 +1,29 @@ +package linea; + +import java.awt.Color; +import java.awt.Graphics; + +public class Bonus extends ObjetGraphique { + + private int largeur = 20; + private int hauteur = 20; + private double vitesseDefilement; + + public Bonus(double x, double y, double vitesse) { + this.x = x; + this.y = y; + this.vitesseDefilement = vitesse; + this.couleur = Color.GREEN; + } + + @Override + public void Afficher(Graphics g) { + g.setColor(this.couleur); + g.fillRect((int)x, (int)y, largeur, hauteur); + } + + @Override + void Animer() { + this.x -= vitesseDefilement; + } +} \ No newline at end of file diff --git a/src/linea/Jeu.java b/src/linea/Jeu.java index 63d134c..a079041 100644 --- a/src/linea/Jeu.java +++ b/src/linea/Jeu.java @@ -2,6 +2,7 @@ package linea; import java.awt.*; import java.awt.event.*; +import java.util.Random; import javax.swing.*; public class Jeu implements KeyListener, ActionListener { @@ -24,9 +25,12 @@ public class Jeu implements KeyListener, ActionListener { protected JLabel labScore; protected int score; - // base de données + //base de données protected GestionnaireBDD bdd = new GestionnaireBDD(); + protected Random random = new Random(); + protected int prochainBonusScore; + protected int utilisateurIdConnecte = -1; protected String identifiantUtilisateurConnecte; public int idCampagneActive = 0; // Retient la campagne (1 = Autoroute, etc.) @@ -161,6 +165,8 @@ public class Jeu implements KeyListener, ActionListener { score = 0; labScore.setText("

score : 0

"); + + this.prochainBonusScore = 300 + random.nextInt(201); } @Override @@ -169,6 +175,22 @@ public class Jeu implements KeyListener, ActionListener { score++; + if (score == prochainBonusScore) { + double xSpawn = 810; + double yLigne = laligne.getHauteurLigneA(xSpawn); + + if (yLigne != -1) { + double yOffset = random.nextBoolean() ? -30 : 30; + double yBonus = yLigne + yOffset; + + Bonus bonus = new Bonus(xSpawn, yBonus, laligne.vitesseDefilement); + ecran.ajouterObjet(bonus); + + this.prochainBonusScore = score + 300 + random.nextInt(201); + } + } + + labScore.setText("

score : " + score + "

"); // Gestion collision simple double hauteurLigne = laligne.getHauteurLigneA(400); @@ -227,4 +249,4 @@ public class Jeu implements KeyListener, ActionListener { @Override public void keyTyped(KeyEvent e) { } -} +} \ No newline at end of file diff --git a/src/linea/MenuPrincipal.java b/src/linea/MenuPrincipal.java index 9d6018c..df45469 100644 --- a/src/linea/MenuPrincipal.java +++ b/src/linea/MenuPrincipal.java @@ -7,7 +7,6 @@ public class MenuPrincipal extends JPanel { private JButton btnPlay; private JButton btnCampaign; private JButton btnLeaderboard; - private JButton btnSettings; private JButton btnQuit; public MenuPrincipal(Jeu jeu) {