1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| //Importation des classes nécessaires.
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.Image;
import java.net.*;
import java.awt.event.*;
public class BomberSrcApplet extends JApplet implements KeyListener
{
//Déclaration des attributs (variables)
private Image fondBomberSRC;
private Image imgPlayer1;
private Image imgPlayer2;
private Image imgPlayer3;
private Image bloc_ind;
private GUI monAffichage;
private Player monPlayer1;
private Player monPlayer2;
private Player monPlayer3;
//Methode init() lancée au démarrage de l'applet
public void init()
{
this.setSize(800,600);
try
{
fondBomberSRC = this.getToolkit().getImage(new URL(getDocumentBase(),"ressources/images/fondBomb.jpg"));
imgPlayer1 = this.getToolkit().getImage(new URL(getDocumentBase(),"ressources/images/sprites/Boy_stand_south.gif"));
imgPlayer2 = this.getToolkit().getImage(new URL(getDocumentBase(),"ressources/images/sprites/Girl_stand_south.gif"));
imgPlayer3 = this.getToolkit().getImage(new URL(getDocumentBase(),"ressources/images/sprites/Sprite_stand_south.gif"));
bloc_ind = this.getToolkit().getImage(new URL(getDocumentBase(),"ressources/images/sprites/bloc.jpg"));
}
catch(MalformedURLException exc)
{
System.out.println("Problème chargement d'image" + exc);
}
fondBomberSRC.getHeight(this);
monAffichage = new GUI (fondBomberSRC);
monPlayer1 = new Player (imgPlayer1, 125, 115);
monPlayer2 = new Player (imgPlayer2, 685, 565);
monPlayer3 = new Player (imgPlayer3, 680, 120);
addKeyListener(this);
this.repaint();
}//fin méthode init()
//Déclaration des méthodes générales
public void keyReleased (KeyEvent touch){};
public void keyTyped (KeyEvent touch){};
public void keyPressed (KeyEvent touch)
{int key = touch.getKeyCode();
switch (key)
{
case KeyEvent.VK_DOWN:System.out.println("bas");
monPlayer1.setPosY(10);
//monPlayer1.setDirection("B");
this.repaint();
break;
case KeyEvent.VK_UP:System.out.println("haut");
monPlayer1.setPosY(-10);
//monPlayer1.setDirection("H");
this.repaint();
break;
case KeyEvent.VK_LEFT:System.out.println("gauche");
monPlayer1.setPosX(-10);
//monPlayer1.setDirection("L");
this.repaint();
break;
case KeyEvent.VK_RIGHT:System.out.println("droite");
monPlayer1.setPosX(10);
//monPlayer1.setDirection("R");
this.repaint();
break;
}
}
public void paint(Graphics g)
{
monAffichage.dessiner(g);
monPlayer1.afficher(g);
monPlayer2.afficher(g);
monPlayer3.afficher(g);
}
}//fin class BomberSRC |
Partager