Advertisement
Guest User

Untitled

a guest
May 9th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.18 KB | None | 0 0
  1. //https://docs.oracle.com/javase/7/docs/api/java/awt/Color.html
  2.  
  3. //Nécessaire pour dessiner les planètes
  4. import java.awt.Graphics2D.*;
  5. import java.awt.Graphics;
  6. //Nécessaire pour MouseInputListener
  7. import java.util.*;
  8. import java.awt.*;
  9. import java.io.*;
  10. import java.awt.event.*;
  11. import javax.swing.*;
  12. import javax.swing.event.*;
  13. import javax.swing.JPanel;
  14. import javax.swing.JFrame;
  15. //Lock des threads
  16. import java.util.concurrent.locks.Condition;
  17. import java.util.concurrent.locks.Lock;
  18. //Importation image de fond
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. import javax.imageio.ImageIO;
  22. import java.awt.image.BufferedImage;
  23. import java.util.Random;
  24. import java.lang.Math.*;
  25.  
  26.  
  27. public class Panel extends JPanel implements MouseInputListener,MouseWheelListener,KeyListener{
  28.     private ArrayList<Planete> pla;
  29.     private ArrayList<Planete> actualiser;
  30.     private ArrayList<GazInterstellaire> gaz;
  31.     private double c = 0.10, xClick, yClick, dx, dy, tmpCam, angleX = 0, angleY = 0, valX, valY;
  32.     private int masseNouvellePlanete = 50, rayonNouvellePlanete = 50;
  33.     private Modele univers;
  34.     private Lock verrou;
  35.     private float zoom = 1f;
  36.     public BufferedImage img, deathStar;
  37.     private double[] camera = new double[3], cameraTranslation = new double[3];
  38.     private static final int INDETERMINATE = -1;
  39.     private int previousKeyPressed = INDETERMINATE, buttonDown = 0, keyTmp = 0, clicPlanete, x, y, tailleTmp;
  40.     private boolean lance = false, rekt;
  41.     private String[] historique;
  42.  
  43.     private double[][] rotationX = new double[3][3];
  44.     private double[][] rotationY = new double[3][3];
  45.     private double[][] InvRotationX = new double[3][3];
  46.     private double[][] InvRotationY = new double[3][3];
  47.  
  48.     private String directionPrecedente = "rieng";
  49.     private BufferedImage image;
  50.     private int compteurScreen = 0, compteurImages;
  51.     private JFrame fen;
  52.  
  53.     public Panel(Modele univers, Lock verrou, InputStream is, int hauteur, int largeur, InputStream deathStar, JFrame fen){
  54.         this.fen = fen;
  55.     pla = univers.getPlanetes();
  56.     System.out.println("Panel : "+pla.size());
  57.     tailleTmp = pla.size();
  58.     univers.setTailleJeu2(tailleTmp);
  59.     this.univers = univers;
  60.     this.verrou = verrou;
  61.     this.camera[0] = largeur/2;
  62.     this.camera[1] = hauteur/2;
  63.     this.camera[2] = 0;
  64.     this.cameraTranslation[0] = 0;
  65.     this.cameraTranslation[1] = 0;
  66.     this.cameraTranslation[2] = 0;
  67.     this.historique = univers.getHistorique();
  68.     try {
  69.             img = ImageIO.read(is);
  70.         this.deathStar = ImageIO.read(deathStar);
  71.         }catch(IOException e){
  72.         e.printStackTrace();
  73.     }
  74.     this.addMouseListener(this);
  75.     this.addMouseMotionListener(this);
  76.     this.addMouseWheelListener(this);
  77.     this.addKeyListener(this);
  78.     this.setFocusable(true);
  79.    
  80.     this.InitialisationMatrices(angleX, angleY);
  81.     }
  82.  
  83.     /**
  84.      * @void Ajout d'une planete
  85.      *
  86.      * Ajoute la planete donnee en parametre a la liste
  87.      * si la planete ne vaut pas nulle, elle sera dans
  88.      * dessinee plus tard
  89.      *
  90.      * @param  oui   Planete qui sera ajoutee
  91.      *
  92.      */
  93.      public void ajouterDraw(Planete p){
  94.       pla.add(p);
  95.      }
  96.  
  97.     public void setTaillePlanete(int ray){
  98.         this.rayonNouvellePlanete = ray;
  99.     }
  100.  
  101.     public void InitialisationMatrices(double angleX, double angleY){
  102.         this.rotationX[0][0] = 1;
  103.         this.rotationX[0][1] = 0;
  104.         this.rotationX[0][2] = 0;
  105.         this.rotationX[1][0] = 0;
  106.         this.rotationX[1][1] = (float)Math.cos(angleX*Math.PI/180);
  107.         this.rotationX[1][2] = (float)(-(Math.sin(angleX*Math.PI/180)));
  108.         this.rotationX[2][0] = 0;
  109.         this.rotationX[2][1] = (float)Math.sin(angleX*Math.PI/180);
  110.         this.rotationX[2][2] = (float)Math.cos(angleX*Math.PI/180);
  111.  
  112.         this.InvRotationX[0][0] = 1;
  113.         this.InvRotationX[0][1] = 0;
  114.         this.InvRotationX[0][2] = 0;
  115.         this.InvRotationX[1][0] = 0;
  116.         this.InvRotationX[1][1] = (float)Math.cos((-angleX)*Math.PI/180);
  117.         this.InvRotationX[1][2] = (float)(-(Math.sin((-angleX)*Math.PI/180)));
  118.         this.InvRotationX[2][0] = 0;
  119.         this.InvRotationX[2][1] = (float)Math.sin((-angleX)*Math.PI/180);
  120.         this.InvRotationX[2][2] = (float)Math.cos((-angleX)*Math.PI/180);
  121.  
  122.         this.rotationY[0][0] = (float)Math.cos(angleY*Math.PI/180);
  123.         this.rotationY[0][1] = 0;
  124.         this.rotationY[0][2] = (float)Math.sin(angleY*Math.PI/180);
  125.         this.rotationY[1][0] = 0;
  126.         this.rotationY[1][1] = 1;
  127.         this.rotationY[1][2] = 0;
  128.         this.rotationY[2][0] = (float)(-(Math.sin(angleY*Math.PI/180)));
  129.         this.rotationY[2][1] = 0;
  130.         this.rotationY[2][2] = (float)Math.cos(angleY*Math.PI/180);
  131.  
  132.         this.InvRotationY[0][0] = (float)Math.cos((-angleY)*Math.PI/180);
  133.         this.InvRotationY[0][1] = 0;
  134.         this.InvRotationY[0][2] = (float)Math.sin((-angleY)*Math.PI/180);
  135.         this.InvRotationY[1][0] = 0;
  136.         this.InvRotationY[1][1] = 1;
  137.         this.InvRotationY[1][2] = 0;
  138.         this.InvRotationY[2][0] = (float)(-(Math.sin((-angleY)*Math.PI/180)));
  139.         this.InvRotationY[2][1] = 0;
  140.         this.InvRotationY[2][2] = (float)Math.cos((-angleY)*Math.PI/180);
  141.     }
  142.  
  143.     public void setRotationX(double angle){
  144.         this.rotationX[1][1] = (float)Math.cos(angleX*Math.PI/180);
  145.         this.rotationX[1][2] = (float)(-(Math.sin(angleX*Math.PI/180)));
  146.         this.rotationX[2][1] = (float)Math.sin(angleX*Math.PI/180);
  147.         this.rotationX[2][2] = (float)Math.cos(angleX*Math.PI/180);
  148.         this.InvRotationX[1][1] = (float)Math.cos((-angleX)*Math.PI/180);
  149.         this.InvRotationX[1][2] = (float)(-(Math.sin((-angleX)*Math.PI/180)));
  150.         this.InvRotationX[2][1] = (float)Math.sin((-angleX)*Math.PI/180);
  151.         this.InvRotationX[2][2] = (float)Math.cos((-angleX)*Math.PI/180);
  152.        
  153.     }
  154.  
  155.     public void setRotationY(double angleY){
  156.         this.rotationY[0][0] = (float)Math.cos(angleY*Math.PI/180);
  157.         this.rotationY[0][2] = (float)Math.sin(angleY*Math.PI/180);
  158.         this.rotationY[2][0] = (float)(-(Math.sin(angleY*Math.PI/180)));
  159.         this.rotationY[2][2] = (float)Math.cos(angleY*Math.PI/180);
  160.         this.InvRotationY[0][0] = (float)Math.cos((-angleY)*Math.PI/180);
  161.         this.InvRotationY[0][2] = (float)Math.sin((-angleY)*Math.PI/180);
  162.         this.InvRotationY[2][0] = (float)(-(Math.sin((-angleY)*Math.PI/180)));
  163.         this.InvRotationY[2][2] = (float)Math.cos((-angleY)*Math.PI/180);
  164.     }
  165.     /**
  166.      * @ void Surcharge des méthodes de l'interface MouseInputListener
  167.      */
  168.     public void mouseClicked(MouseEvent e){
  169.         xClick = (double)(e.getX());
  170.             yClick = (double)(e.getY());
  171.     }
  172.     public void mouseExited(MouseEvent e){
  173.  
  174.     }
  175.     public void mouseEntered(MouseEvent e){
  176.  
  177.     }
  178.     public void mouseReleased(MouseEvent e){
  179.         double []tmp = {xClick,yClick,0};
  180.         tmp = InvCoordGraph(tmp);
  181.         double xTmp = tmp[0], yTmp = tmp[1], zTmp = tmp[2];
  182.         if(univers.getMode() && buttonDown == MouseEvent.BUTTON1 && !univers.getJeuA()){
  183.             pla.add(new Planete(masseNouvellePlanete,new Position(xTmp,yTmp,zTmp),new Position(0,0,0),new Position(dx/100,dy/100,0),rayonNouvellePlanete,(int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
  184.             univers.ajouterHistorique("Nouvelle Planète !");
  185.         }
  186.         else if(univers.getMode() && buttonDown == MouseEvent.BUTTON1 && univers.getJeuA()){
  187.             univers.setTailleJeu(1);
  188.             univers.ajouterHistorique("Nouvelle Planète !");
  189.             pla.add(new Planete(masseNouvellePlanete,new Position((xClick-this.camera[0])/zoom,(yClick-this.camera[1])/zoom,0),new Position(0,0,0),new Position(dx/25,dy/25,0),rayonNouvellePlanete,(int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
  190.         }
  191.         if(!univers.getMode() && buttonDown == MouseEvent.BUTTON1 && lance && !univers.getJeuA()){
  192.             pla.get(clicPlanete).getVitesse().setX(dx/50);
  193.             pla.get(clicPlanete).getVitesse().setY(dy/50);
  194.             lance = false;
  195.             univers.ajouterHistorique("Modification de la vitesse de la planètes "+clicPlanete+" !");
  196.         }
  197.         this.camera[0] += this.cameraTranslation[0];
  198.         this.camera[1] += this.cameraTranslation[1];
  199.         this.cameraTranslation[0] = 0;
  200.         this.cameraTranslation[1] = 0;
  201.         dx = 0;
  202.         dy = 0;
  203.     }
  204.     /**
  205.      * @ void récupération des coordonnées de l'endroit cliqué sur le JPanel
  206.      */
  207.     public void mousePressed(MouseEvent e){
  208.         buttonDown = e.getButton();
  209.         xClick = (double)(e.getX());
  210.         yClick = (double)(e.getY());
  211.         double []tmp = {xClick,yClick,0};
  212.         tmp = InvCoordGraph(tmp);
  213.         int test1 = (int)((tmp[0]-this.camera[0])/zoom);
  214.         int test2 = (int)((tmp[1]-this.camera[1])/zoom);
  215.         if(buttonDown == MouseEvent.BUTTON1 && !univers.getMode() && !univers.getJeuA()){
  216.             for(int j = 0; j < pla.size(); j++){
  217.                 Planete actuel = pla.get(j);
  218.                 double [] coord = {actuel.getPos().getX(),actuel.getPos().getY(),actuel.getPos().getZ()};
  219.                 coord = CoordGraph(coord);
  220.                 double xTmp = coord[0], yTmp = coord[1];
  221.                 if(test1 > xTmp-(pla.get(j).getRayon2())*2 && test1 < xTmp+(pla.get(j).getRayon2()) && test2 > yTmp-(pla.get(j).getRayon2())*2 && test2 < yTmp+(pla.get(j).getRayon2())){
  222.                     lance = true;
  223.                     clicPlanete = j;
  224.                 }
  225.             }
  226.         }
  227.     }
  228.     public void mouseMoved(MouseEvent e){
  229.         valX = e.getX()-this.camera[0];
  230.         valY = e.getY()-this.camera[1];
  231.         double x = e.getX()-camera[0], y = e.getY()-camera[1];
  232.         int test1 = (int)((x-this.camera[0])/zoom);
  233.         int test2 = (int)((y-this.camera[1])/zoom);
  234.         for(int j = 0; j < pla.size(); j++){
  235.         if(test1 > pla.get(j).getPos().getX()-(pla.get(j).getRayon2())*2 && test1 < pla.get(j).getPos().getX()+(pla.get(j).getRayon2()) && test2 > pla.get(j).getPos().getY()-(pla.get(j).getRayon2())*2 && test2 < pla.get(j).getPos().getY()+(pla.get(j).getRayon2())){
  236.             //System.out.println("Planète "+j+" : masse = "+pla.get(j).getMasse()+"x10^24Kg, rayon = "+pla.get(j).getRayon2()*100+"Km");
  237.         }
  238.         }
  239.     }
  240.     /**
  241.      * @ void récupération du vecteur de coordonnées fait avec un Drag'n'Drop à la souris
  242.      */
  243.     public void mouseDragged(MouseEvent e){
  244.         dx = (e.getX() - xClick);
  245.         dy = (e.getY() - yClick);
  246.         if(buttonDown == MouseEvent.BUTTON3){
  247.             this.cameraTranslation[0] = dx;
  248.             this.cameraTranslation[1] = dy;
  249.         }
  250.     }
  251.     public void mouseWheelMoved(MouseWheelEvent e){
  252.         if(e.getWheelRotation() < 0){
  253.             this.setZoom(1.05f);
  254.             this.camera[2] += 1;
  255.         }
  256.         else{
  257.             this.setZoom(0.95f);
  258.             this.camera[2] -= 1;
  259.         }
  260.     }
  261.     public void keyTyped(KeyEvent evt){
  262.         keyTmp = evt.getKeyCode();
  263.     }
  264.     public void keyPressed(KeyEvent evt){
  265.         if(previousKeyPressed == INDETERMINATE){
  266.                     previousKeyPressed = evt.getKeyCode();
  267.         }
  268.                 //else if(previousKeyPressed != evt.getKeyCode() && previousKeyPressed == KeyEvent.VK_CONTROL && !univers.getJeuA()){
  269.         else if(!univers.getJeuA()){
  270.             switch(evt.getKeyCode()){
  271.                 case KeyEvent.VK_LEFT :
  272.                         angleY -= 1;
  273.                         setRotationY(angleY);
  274.                         break;
  275.                 case KeyEvent.VK_RIGHT :
  276.                         angleY += 1;
  277.                         setRotationY(angleY);
  278.                         break;
  279.                 case KeyEvent.VK_DOWN :
  280.                         angleX -= 1;
  281.                         setRotationX(angleX);
  282.                         break;
  283.                 case KeyEvent.VK_UP :
  284.                         angleX += 1;
  285.                         setRotationX(angleX);
  286.                         break;
  287.                 default : break;
  288.             }
  289.                 }
  290.     }
  291.     public void keyReleased(KeyEvent evt){
  292.         keyTmp = 0;
  293.         if(previousKeyPressed == evt.getKeyCode()){
  294.             previousKeyPressed = INDETERMINATE;
  295.         }
  296.     }
  297.     /**
  298.      * @ void réglage du zoom
  299.      * cette méthode set le zoom en le multipliant
  300.      * par la valeur envoyée en argument
  301.      * par le actionListener de "Zoom Avant/Arrière"
  302.      */
  303.     public void setZoom(float z){
  304.     this.zoom *= z;
  305.     }
  306.     public void setZoomDefault(){
  307.     this.zoom = 1f;
  308.     }
  309.  
  310.     /**
  311.      * @ArrayList<Planete> tri de liste de planetes
  312.      *
  313.      * cette methode trie l'array list de toutes les planetes
  314.      * en ordre de sa valeur de Z pour l'orbite
  315.      *
  316.      * @param pla  un ArrayList, avec des objets de type Planete, qui sera trie
  317.      *
  318.      */
  319.     private void triList(){
  320.     Collections.sort(pla, new PlaneteComparator(this));
  321.     }
  322.    
  323.     /**
  324.      * @void Affichage des planetes
  325.      *
  326.      * cette methode lit l'array list de toutes les planetes
  327.      * deja creees et les dessine grace a un graphics et
  328.      * avec valeurs donnees par l'utilisateur
  329.      *
  330.      * @param g   ----text----
  331.      *
  332.      */
  333.    
  334.     public void paintComponent(Graphics g){
  335.     System.out.println("Panel paint : "+pla.size());
  336.     g.drawImage(img, 0, 0, null);
  337.     g.setColor(new Color(0,200,200));
  338.     triList();
  339.     g.fillOval((int)(camera[0]+cameraTranslation[0]),(int)(camera[1]+cameraTranslation[1]),8,8);
  340.     g.drawImage(deathStar,(int)(this.rotationX[0][0]*200*zoom+camera[0]+cameraTranslation[0]),(int)(this.rotationY[1][1]*200*zoom+camera[1]+cameraTranslation[1]), null);
  341.     g.setColor(new Color(128, 128, 128, 200));
  342.     for(int j = 0; j < gaz.size(); j++){
  343.             GazInterstellaire actuel = gaz.get(j);
  344.                     double [] coord = {actuel.getPos().getX(),actuel.getPos().getY(),actuel.getPos().getZ()};
  345.         coord = CoordGraph(coord);
  346.         double xTmp = coord[0], yTmp = coord[1];
  347.             //double xTmp = (actuel.getPos().getX())*zoom+camera[0]+cameraTranslation[0], yTmp = (actuel.getPos().getY())*zoom+camera[1]+cameraTranslation[1];
  348.             g.fillOval((int)(xTmp+cameraTranslation[0]),
  349.                 (int)(yTmp+cameraTranslation[1]),
  350.                 (int)(actuel.getRayon2()*zoom),
  351.                 (int)(actuel.getRayon2()*zoom));
  352.     }
  353.     for(int i = 0; i < pla.size(); i++){
  354.             Planete actuel = pla.get(i);
  355.             //double xTmp = (actuel.getPos().getX())*zoom+camera[0]+cameraTranslation[0], yTmp = (actuel.getPos().getY())*zoom+camera[1]+cameraTranslation[1];
  356.  
  357.         double [] coord = {actuel.getPos().getX(),actuel.getPos().getY(),actuel.getPos().getZ()};
  358.         coord = CoordGraph(coord);
  359.         double xTmp = coord[0], yTmp = coord[1];
  360.         g.setColor(new Color((int)(actuel.getRouge()),(int)(actuel.getVert()),(int)(actuel.getBleu())));           
  361.             g.fillOval((int)(xTmp+cameraTranslation[0]),
  362.                    (int)(yTmp+cameraTranslation[1]),
  363.                    (int)((actuel.getRayon2()+(actuel.getPos().getZ())/10)*zoom),
  364.                    (int)((actuel.getRayon2()+(actuel.getPos().getZ())/10)*zoom));
  365.     }
  366.  
  367.     Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
  368.         int hauteur = (int)tailleEcran.getHeight();    
  369.         int largeur = (int)tailleEcran.getWidth();
  370.  
  371.     String textScore = "Score : " + univers.getPoints();
  372.     String textSouris = "X : " + valX + ", Y : " + valY;
  373.     g.setColor(Color.WHITE);
  374.     if(univers.getJeuA()){
  375.         g.drawString(textScore + "        " + textSouris, largeur/2-100, 20);
  376.     }else{
  377.         g.drawString(textSouris, largeur/2-50, 20);
  378.         g.drawString("Zoom : "+this.zoom,largeur/2-250, 20);
  379.     }
  380.  
  381.     g.setColor(Color.WHITE);
  382.     int decalage = 30;
  383.     //if(univers.getJeuA()){
  384.         for(int i=0; i<5; i++){
  385.         String s = this.historique[i];
  386.         if(s.equals("Nouvelle Planète !") || s.equals("Votre vidéo est enregistrée !") || s.equals("Lecture") || s.equals("Lecture de la musique")){
  387.             g.setColor(Color.GREEN); //vert
  388.         }else if(s.equals("La vidéo n'a pas pu être sauvée") || s.equals("En pause") || s.equals("Musique en Pause")){
  389.             g.setColor(Color.RED); //rouge
  390.         }else if(s.equals("Fichier ouvert!")){
  391.             g.setColor(Color.ORANGE); //orange
  392.         }else if(s.equals("Vous jouez à Système Stable !")){
  393.             g.setColor(Color.CYAN);
  394.         }else if(s.equals("Fin du jeu vous avez marqué : ")){
  395.             g.setColor(Color.YELLOW);
  396.         }
  397.         if(!s.equals("Fin du jeu vous avez marqué : ")){
  398.             g.drawString(s, largeur-300, 20 + decalage);
  399.         }else{
  400.             g.drawString(s+univers.getPoints(), largeur-300, 20 + decalage);
  401.         }
  402.         g.setColor(Color.WHITE);
  403.         decalage += 20;
  404.         }
  405.         //}
  406.    
  407.    
  408.  
  409.     g.dispose();
  410.     }
  411.  
  412.    
  413.     public double[] sommeCoord(double []coord, double [] cam){
  414.         coord[0] += cam[0];
  415.         coord[1] += cam[1];
  416.         coord[2] += cam[2];
  417.         return coord;
  418.     }
  419.     public double[] sommeCoord2(double []coord, double [] cam){
  420.         coord[0] += -(cam[0]);
  421.         coord[1] += -(cam[1]);
  422.         coord[2] += -(cam[2]);
  423.         return coord;
  424.     }
  425.     public double[] produitCoord(double []coordActu, double [][] coordMatrice){
  426.         coordActu[0] = coordActu[0]*coordMatrice[0][0] + coordActu[1]*coordMatrice[1][0] + coordActu[2]*coordMatrice[2][0];
  427.         coordActu[1] = coordActu[0]*coordMatrice[0][1] + coordActu[1]*coordMatrice[1][1] + coordActu[2]*coordMatrice[2][1];
  428.         coordActu[2] = coordActu[0]*coordMatrice[0][2] + coordActu[1]*coordMatrice[1][2] + coordActu[2]*coordMatrice[2][2];
  429.         return coordActu;
  430.     }
  431.     /*public double[] produitZoom(double coord[], double zoom, boolean inverse){
  432.         if(inverse){
  433.             coord[0] *= zoom;
  434.             coord[1] *= zoom;
  435.             coord[2] *= zoom;
  436.         }else{
  437.             coord[0] /= zoom;
  438.             coord[1] /= zoom;
  439.             coord[2] /= zoom;
  440.         }return coord;
  441.     }*/
  442.     public double[] CoordGraph(double coordM[]){
  443.         double []coordMatrice = produitCoord(coordM,this.rotationX);
  444.         coordMatrice = produitCoord(coordMatrice,this.rotationY);
  445.         coordMatrice = sommeCoord(coordMatrice,this.camera);
  446.         //coordMatrice = produitZoom(coordMatrice,this.zoom,true);
  447.         return coordMatrice;
  448.     }
  449.  
  450.     public double[] InvCoordGraph(double coordM[]){
  451.         //double[] coordMatrice2 = produitZoom(coordM,this.zoom,false);
  452.         double[] coordMatrice2 = sommeCoord2(coordM,this.camera);
  453.         coordMatrice2 = produitCoord(coordMatrice2,this.InvRotationY);
  454.         coordMatrice2 = produitCoord(coordMatrice2,this.InvRotationX);
  455.         return coordMatrice2;
  456.     }
  457.  
  458.     /**
  459.      * @void Actualisation
  460.      *
  461.      * actualise la fenetre
  462.      *
  463.      */
  464.     public void actualiserPlanete(){
  465.         repaint();
  466.     }
  467.  
  468.     /**
  469.      * @void Affichage des planetes
  470.      *
  471.      * cette methode lit l'array list des planetes et
  472.      * les ajoute a la fenetre pour pouvoir etre
  473.      * dessinees plus tard
  474.      *
  475.      * Prend un screenshot de la fenêtre pour en faire un film après
  476.      *
  477.      */
  478.     public void afficher(){
  479.         verrou.lock();
  480.         if(univers.isThereACollision()){
  481.             pla = univers.getPlanetes();
  482.             univers.isCollisionne();
  483.         }
  484.         if(univers.getGaz() != null){
  485.         gaz = univers.getGaz();
  486.         }
  487.         if(univers.getRekt() && compteurScreen == 0){
  488.             image = new BufferedImage(this.getWidth(), this.getHeight(),BufferedImage.TYPE_INT_RGB);
  489.         }
  490.         if(univers.getRekt()){
  491.             compteurScreen++;
  492.         }
  493.  
  494.         if(compteurScreen == 25 && univers.getRekt()){
  495.         try
  496.         {
  497.             this.paint(image.createGraphics());
  498.             ImageIO.write(image, "BMP",new File("./Capture/"+compteurImages+".bmp"));
  499.         }
  500.         catch(Exception ex)
  501.         {
  502.             ex.printStackTrace();
  503.         }
  504.         compteurImages++;
  505.         compteurScreen = 0;
  506.         }
  507.         verrou.unlock();
  508.     }
  509. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement