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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
package model;
import sun.audio.AudioPlayer;
import main.Principale;
import music.Musicothèque;
public class Launch extends Thread {
private static int X;
private static int Y;
public static boolean stop;
public static String name;
public Launch()
{
//lancement de la balle par defaut :
X=2;
Y=-1;
stop=false;
}
public void run() {
Plateau.b.caught=false;
while(!stop) {
try {
Thread.sleep(2*Math.abs(X)+1,5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//collision plateau
if(Plateau.b.getCoordonnee().getX()<=0)
X=-X;
if(Plateau.b.getCoordonnee().getX()>=500-Plateau.b.getSize())
X=-X;
if(Plateau.b.getCoordonnee().getY()<=0)
Y=-Y;
if(Plateau.b.getCoordonnee().getY()>=610-Plateau.b.getSize()) //perdu !
Principale.lose();
//collision paddle (si la balle n est pas caught
if(!Plateau.b.caught)
{if(Plateau.b.getCoordonnee().getY()+Plateau.b.getSize()==Plateau.v.getCoordonnees().getY()&&Plateau.b.getCoordonnee().getX()+Plateau.b.getSize()>=Plateau.v.getCoordonnees().getX() &&Plateau.b.getCoordonnee().getX()-Plateau.b.getSize()<=Plateau.v.getCoordonnees().getX()+Plateau.v.getWidth() )
{Y=-Y; ;
Musicothèque.paddle();
if(Plateau.b.getCoordonnee().getX()>Plateau.v.getCoordonnees().getX()+Plateau.v.getWidth()/2)
{if(X==-1) X=1;else X=X+1;}
else
{ if(X==1) X=-1;else X=X-1;}
}
}
//collison brique:
for(int cpt=0;cpt<Plateau.Blist.size();cpt++)
{
int test=Plateau.Blist.get(cpt).touch();
if( test != -1)
{Principale.p.destruction(cpt);
Musicothèque.brick();
Plateau.pl.setScore(Plateau.pl.getScore()+5);
if (Plateau.Blist.size()==0){
Principale.p.setClear(true);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//lancement du niveau suivant:
Principale.next();
}
if(test==0)
{
X=-X;
}
else Y=-Y;
}
}
System.out.println(name);
//deplacement
Plateau.b.setCoordonnee(new Coor(Plateau.b.getCoordonnee().getX()+X,Plateau.b.getCoordonnee().getY()+Y));
}
}
} |
Partager