Jeu de type "TileGame" (Mario Bross style)- Affichage des scores

grattier Messages postés 9 Date d'inscription mardi 25 mai 2004 Statut Membre Dernière intervention 7 août 2006 - 10 août 2004 à 04:38
grattier Messages postés 9 Date d'inscription mardi 25 mai 2004 Statut Membre Dernière intervention 7 août 2006 - 10 août 2004 à 21:48
Bonjour, je suis actuellement entrain de faire une petite jeu du même style que Mario Bross (toujours au centre d'une map et on bouge de gauche à droite avec des petits monstres) et je veux faire afficher des scores. Le jeu fonctionne actuellement mais je ne suis pas capable d'ajouter ne section en haut qui reste toujours sur l'écran et qui affiche et actualise le nombre de vies/scores/etc...

Voici un quelques codes qui vous montre comment laffiche marche:

PS: La classe ecran est en fait:

public ControleurEcran() {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
materiel = environment.getDefaultScreenDevice();
}

et sa methode qu iaffecte le plein ecran:

public void setFullScreen(DisplayMode modeAffichage) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
frame.setResizable(false);

materiel.setFullScreenWindow(frame);

if (modeAffichage!= null &&
materiel.isDisplayChangeSupported())
{
try {
materiel.setDisplayMode(modeAffichage);
}
catch (IllegalArgumentException ex) { }
// fix pour mac os x
frame.setSize(displayMode.getWidth(),
displayMode.getHeight());
}

catch (InvocationTargetException ex) {
// ignore
}

Et ma classe Noyeau...

public void demarrer() {
try {
init();
boucleJeu();
}
finally {
ecran.restoreEcran();
sortiPrecipite();
}
}

public void init() {
ecran = new ControleurEcran();
DisplayMode modesAffichage =
ecran.trouverPremierModePorrible(POSSIBLE_MODES);
ecran.setPleinEcran(modesAffichage);

Window window = ecran.getFenetrePleinEcran();
window.setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));
window.setBackground(Color.blue);
window.setForeground(Color.white);

estEnMarche= true;
}

public void gameLoop() {
long tempDepart= System.currentTimeMillis();
long tempActuel= startTime;

while (estEnMarche) {
long tempPasse =
System.currentTimeMillis() - tempActuel;
tempActuel+= tempPasse ;

update(tempPasse);

Graphics2D g = ecran.getGraphics();
draw(g);
g.dispose();
ecran.update();
}
}

Bref comment je peux ajouter des JLabel ou autres par dessus un Graphique 2D....

2 réponses

cid019 Messages postés 237 Date d'inscription mercredi 2 juin 2004 Statut Membre Dernière intervention 11 juillet 2006
10 août 2004 à 11:51
Essayes de t'inspirer de ce source...

class Scores extends Panel implements Observer
{
private Etiquette lblScore;
private Etiquette lblNbVies;
private Etiquette lblNbFant;
private Etiquette lblNbPastilles;
private JComboBox cmbNiveau;

public Scores(int nb)
{
setFocusable(false);
setLayout(new BorderLayout());
setBackground(Color.BLACK);
setForeground(Color.RED);

Container c = new Container();
c.setLayout(new GridLayout(nb*2+3,2,5,5));
c.add(new Label(""));
c.add(new Label(""));
c.add(new Label("Score :"));
lblScore = new Etiquette("0", c);
c.add(new Label("Vies :"));
lblNbVies = new Etiquette("0", c);
c.add(new Label("Fantomes attrapes:"));
lblNbFant = new Etiquette("0", c);
c.add(new Label("Pastilles :"));
lblNbPastilles = new Etiquette("0",c);
c.add(new Label(""));
c.add(new Label(""));

add(c, BorderLayout.CENTER);

}

public void init()
{
//Niveau niveau = Jeu.getInstance().getNiveau();
Partie p = Jeu.getInstance().getPartie();
Labyrinthe l = Jeu.getInstance().getLabyrinthe();

lblScore.setText(new Integer(p.getScore()).toString());
lblNbVies.setText(new Integer(p.getCurrentNiveau().getVies()).toString());
lblNbFant.setText(new Integer(p.getCurrentNiveau().getFantomesManges()).toString());
lblNbPastilles.setText(new Integer(l.getNombrePastilles()).toString());
}

public void update(Observable o, Object arg)
{
//Niveau niveau = (Niveau)arg;
Partie p = (Partie)arg;
//Labyrinthe l = (Labyrinthe)arg;

lblScore.setText(new Integer(p.getScore()).toString());
lblNbVies.setText(new Integer(p.getCurrentNiveau().getVies()).toString());
lblNbFant.setText(new Integer(p.getCurrentNiveau().getFantomesManges()).toString());
//lblNbPastilles.setText(new Integer(l.getNombrePastilles()).toString());
}
}

c'est une classe affichant le nombrede vies et le sscore .
Cette classe a servi lors d'un projet de Pacman

Par contre une chose est sure tu ne peux afficher des Label combine a un graphics. j'ai deja essaye il privilegie un des deux.

cid019
0
grattier Messages postés 9 Date d'inscription mardi 25 mai 2004 Statut Membre Dernière intervention 7 août 2006
10 août 2004 à 21:48
C'est bon j'ai reussi. Je vais tout simplement ajouter une image sur laquelle je vais faire des g.drawstring... merci
0
Rejoignez-nous