petit carré vert en bonus sans possibilité de le reccuperer
This commit is contained in:
29
src/linea/Bonus.java
Normal file
29
src/linea/Bonus.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package linea;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.util.Random;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Jeu implements KeyListener, ActionListener {
|
public class Jeu implements KeyListener, ActionListener {
|
||||||
@@ -24,9 +25,12 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
protected JLabel labScore;
|
protected JLabel labScore;
|
||||||
protected int score;
|
protected int score;
|
||||||
|
|
||||||
// base de données
|
//base de données
|
||||||
protected GestionnaireBDD bdd = new GestionnaireBDD();
|
protected GestionnaireBDD bdd = new GestionnaireBDD();
|
||||||
|
|
||||||
|
protected Random random = new Random();
|
||||||
|
protected int prochainBonusScore;
|
||||||
|
|
||||||
protected int utilisateurIdConnecte = -1;
|
protected int utilisateurIdConnecte = -1;
|
||||||
protected String identifiantUtilisateurConnecte;
|
protected String identifiantUtilisateurConnecte;
|
||||||
public int idCampagneActive = 0; // Retient la campagne (1 = Autoroute, etc.)
|
public int idCampagneActive = 0; // Retient la campagne (1 = Autoroute, etc.)
|
||||||
@@ -161,6 +165,8 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
|
|
||||||
score = 0;
|
score = 0;
|
||||||
labScore.setText("<html><h3>score : 0</h3></html>");
|
labScore.setText("<html><h3>score : 0</h3></html>");
|
||||||
|
|
||||||
|
this.prochainBonusScore = 300 + random.nextInt(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,6 +175,22 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
|
|
||||||
score++;
|
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("<html><h3>score : " + score + "</h3></html>");
|
labScore.setText("<html><h3>score : " + score + "</h3></html>");
|
||||||
// Gestion collision simple
|
// Gestion collision simple
|
||||||
double hauteurLigne = laligne.getHauteurLigneA(400);
|
double hauteurLigne = laligne.getHauteurLigneA(400);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ public class MenuPrincipal extends JPanel {
|
|||||||
private JButton btnPlay;
|
private JButton btnPlay;
|
||||||
private JButton btnCampaign;
|
private JButton btnCampaign;
|
||||||
private JButton btnLeaderboard;
|
private JButton btnLeaderboard;
|
||||||
private JButton btnSettings;
|
|
||||||
private JButton btnQuit;
|
private JButton btnQuit;
|
||||||
|
|
||||||
public MenuPrincipal(Jeu jeu) {
|
public MenuPrincipal(Jeu jeu) {
|
||||||
|
|||||||
Reference in New Issue
Block a user