Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void run() {
- int deg, dist;
- int deg2, dist2;
- int xtmp, ytmp;
- int i;
- int v1_x, v1_y;
- double dist_test;
- TortueAmelioree PorteBalle = new TortueAmelioree();
- TortueAmelioree APorteBalle = new TortueAmelioree();
- TortueAmelioree tort_proche = new TortueAmelioree();
- TortueAmelioree tort_proche2 = new TortueAmelioree();
- double dist_min = 100000;
- double dist_min2 = 100000;
- double dist_tmp;
- double dist_tmp2;
- ArrayList<TortueAmelioree> equipeballe = new ArrayList<TortueAmelioree>();
- ArrayList<TortueAmelioree> equipenonballe = new ArrayList<TortueAmelioree>();
- ArrayList<TortueAmelioree> equipetmp = new ArrayList<TortueAmelioree>();
- equipeballe = this.equipe1;
- equipenonballe = this.equipe2;
- while(isRuning) {
- for (Iterator it = equipeballe.iterator(); it.hasNext();){
- TortueAmelioree tortame = (TortueAmelioree) it.next();
- xtmp = tortame.getPositionX();
- ytmp = tortame.getPositionY();
- do{
- tortame.setPositionX(xtmp);
- tortame.setPositionY(ytmp);
- deg = (int) (Math.random() * 90);
- dist = (int) (Math.random() * 5);
- if (Math.random() > 0.95) {
- if (Math.random() > 0.5) {
- tortame.gauche(deg);
- } else {
- tortame.droite(deg);
- }
- }
- tortame.avancer(dist);
- if (this.balle.GetJoueur() == tortame){
- PorteBalle = tortame;
- }
- }while(tortame.getPositionX() < 5 || tortame.getPositionY() < 5 || tortame.getPositionX() > feuille.getWidth()-5 || tortame.getPositionY() > feuille.getHeight()-5);
- }
- i = 0;
- for (Iterator it = equipenonballe.iterator(); it.hasNext();){
- TortueAmelioree tortame = (TortueAmelioree) it.next();
- xtmp = tortame.getPositionX();
- ytmp = tortame.getPositionY();
- do{
- tortame.setPositionX(xtmp);
- tortame.setPositionY(ytmp);
- if ((equipeballe.get(i).getPositionY() - tortame.getPositionY()) == 0)
- {tortame.setPositionY(ytmp + 1);}
- v1_x = equipeballe.get(i).getPositionX() - tortame.getPositionX();
- v1_y = equipeballe.get(i).getPositionY() - tortame.getPositionY();
- //deg2 = (int) Math.acos(scal / (v1_norm * v1_norm));
- dist_test = Math.sqrt((v1_x*v1_x)+(v1_y*v1_y));
- deg2 = (int) (Math.acos(Math.cos(Math.abs(v1_x)/dist_test))* 180/Math.PI);
- if(v1_x < 0) {
- //Coté gauche du point
- if(v1_y < 0) {
- //En haut a gauche
- tortame.setDir(180+deg2);
- }
- else {
- //En bas a gauche
- tortame.setDir(90+deg2);
- }
- }
- else {
- //Coté droite du point
- if(v1_y < 0) {
- //En haut a droite
- tortame.setDir(270+deg2);
- }
- else {
- //En bas a droite
- tortame.setDir(deg2);
- }
- }
- /*
- if (equipeballe.get(i).getPositionX() == tortame.getPositionX())
- {
- deg2 = 0;
- }
- else {
- deg2 = (int) Math.toDegrees(
- Math.atan2(
- (equipeballe.get(i).getPositionY() - tortame.getPositionY()),
- (equipeballe.get(i).getPositionX() - tortame.getPositionX())
- )
- );
- }
- */
- /* deg2 = (int) Math.tan((equipeballe.get(i).getPositionY() - tortame.getPositionY()) / (equipeballe.get(i).getPositionX() - tortame.getPositionX()));
- System.out.printf(i+" : "+deg2);
- dist2 = (int) (Math.random() * 5);
- if (Math.random() > 0.05) {
- if (Math.random() > 0.5) {
- tortame.setDir(180 + deg2 - (int)(Math.random() * 5));
- } else {
- tortame.setDir(180 + deg2 + (int)(Math.random() * 5));
- }
- }
- */
- // deg2 = (int) (Math.random() * 90);
- dist2 = (int) (Math.random() * 5);
- if (Math.random() > 0.95) {
- tortame.gauche(deg2);
- }
- tortame.avancer(dist2);
- if (this.balle.GetJoueur() == tortame){
- PorteBalle = tortame;
- }
- }while(tortame.getPositionX() < 5 || tortame.getPositionY() < 5 || tortame.getPositionX() > feuille.getWidth()-5 || tortame.getPositionY() > feuille.getHeight()-5);
- i++;
- }
- for (Iterator it = PorteBalle.get_liste().iterator(); it.hasNext();){
- TortueAmelioree tortame = (TortueAmelioree) it.next();
- dist_tmp = PorteBalle.calcEuclDistance(tortame);
- if (dist_tmp < dist_min) {
- dist_min = dist_tmp;
- tort_proche = tortame;
- }
- }
- for (Iterator it = equipenonballe.iterator(); it.hasNext();){
- TortueAmelioree tortame = (TortueAmelioree) it.next();
- dist_tmp2 = PorteBalle.calcEuclDistance(tortame);
- if (dist_tmp2 < dist_min2) {
- dist_min2 = dist_tmp2;
- tort_proche2 = tortame;
- }
- }
- if (dist_min2 < 80){
- APorteBalle = PorteBalle;
- this.balle.SetJoueur(tort_proche2);
- this.balle.setColor(tort_proche2.getColor());
- PorteBalle = tort_proche2;
- equipetmp = equipenonballe;
- equipenonballe = equipeballe;
- equipeballe = equipetmp;
- }
- else{
- if (dist_min < 100 && APorteBalle != tort_proche){
- APorteBalle = PorteBalle;
- this.balle.SetJoueur(tort_proche);
- this.balle.setColor(tort_proche.getColor());
- PorteBalle = tort_proche;
- }
- }
- this.balle.setPositionX(PorteBalle.getPositionX() + 20);
- this.balle.setPositionY(PorteBalle.getPositionY() + 5);
- dist_min = 100000;
- this.feuille.repaint();
- try {
- Thread.sleep(1000/30);
- } catch (InterruptedException ex) {
- Logger.getLogger(JeuEquipe.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment