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
| import java.awt.*;
import javax.swing.ImageIcon;
public class Projectils implements IDrawable{
private Image image = new ImageIcon("./missile.png").getImage();
private int x, y, largeur = 10, hauteur = 20; /** x et y coordonnée de lancement */
private Dimensions dim;
private Player player;
private GameWindow gameWindow;
private Panneau pan;
private myThread th;
Projectils(int x, int y, Panneau pan){
System.out.println("Creation de l'objet \" Projectils \" ! ");
this.x = x;
this.y = y;
this.pan = pan;
}
public void draw(Graphics g){
g.drawImage(image, x, y, null);
}
/** retourne un rectangle englobant le projectil */
public Rectangle getRectangle(){
return (new Rectangle(this.x,this.y,largeur,hauteur));
}
public void goTrajectoire(){
/** Déplacement du projectile */
th = new myThread();
/** + 15 pour center plus ou moins le missile devant le vaisseau*/
th.getCoord(x + 5,y);
th.getFrameDim(dim);
th.getProjectil(this);
th.getGameWindow(gameWindow);
th.getPanneau(pan);
/** on envoie notre projectil dans la liste des drawables */
pan.addDrawableProjectil(this);
/** lancement du thread de deplacement du projectile */
th.start();
}
public void getFrameDim(Dimensions dim){
this.dim = dim;
}
public void setCoord( int x, int y){
this.x = x;
this.y = y;
}
[...]
} |