Guest User

ABSURD BUG

a guest
Feb 6th, 2026
64
0
248 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.73 KB | Source Code | 0 0
  1. package terzaFSimulator;
  2.  
  3. import javax.swing.ImageIcon;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6.  
  7. import java.awt.Color;
  8. import java.awt.Rectangle;
  9.  
  10. import javax.swing.*;
  11.  
  12. public class CombatPanel extends JPanel {
  13.     JPanel areAnima;
  14.     JPanel areaTexture;
  15.     JPanel areaScelte;
  16.     JPanel areaVita;
  17.     JPanel areAttacco;
  18.    
  19.     JButton fightButton;
  20.     JButton actButton;
  21.     JButton itemButton;
  22.     JButton mercyButton;
  23.     static boolean combat = false;
  24.     boolean animOcchi1 = false;
  25.     boolean animOcchi2 = false;
  26.    
  27.     Sprite occhioSu = null;
  28.     Sprite occhioGiù = null;
  29.     Sprite occhioDestra = null;
  30.     Sprite occhioSinistra = null;
  31.    
  32.     Sprite occhioSu2 = null;
  33.     Sprite occhioGiù2 = null;
  34.     Sprite occhioDestra2 = null;
  35.     Sprite occhioSinistra2 = null;
  36.    
  37.     Rectangle boxAnima;
  38.     int xInizio = 140;
  39.     int yInizio = 10;
  40.    
  41.     int sizeX = 600;
  42.     int sizeY = 180;
  43.    
  44.    Sprite tempInversione1 = null; //4 Possibili inversionicaricate contemporaneamente
  45.    Sprite tempInversione2 = null;
  46.    Sprite tempInversione3 = null;
  47.    Sprite tempInversione4 = null;
  48.    
  49.     Enemy e;
  50.     CombatPanel(Enemy e) {
  51.         this.e = e;
  52.         combat = true;
  53.         creaAmbiente();
  54.     }
  55.    
  56.     void creaAmbiente() {
  57.         this.setLayout(null);
  58.  
  59.         areaTexture = new JPanel();
  60.         areaTexture.setBounds(0, 0, 880, 268);
  61.         areaTexture.setBackground(new Color(0, 0, 0, 0));
  62.         areaTexture.setLayout(null);
  63.         int numLabel = 0;
  64.         for(Sprite sprite: e.sprites) {
  65.             sprite.setOpaque(false);
  66.             if(sprite.getTag().contains("occhio")) {
  67.                 raccogliOcchi(sprite, numLabel);
  68.                 numLabel++;
  69.                 continue;
  70.             }else if(sprite.getTag().contains("inverti_")) {
  71.                 raccoglInversioni(sprite, numLabel);
  72.                 numLabel++;
  73.                 continue;
  74.             }
  75.             sprite.setBounds(e.posSprites[numLabel][0], e.posSprites[numLabel][1], e.posSprites[numLabel][2], e.posSprites[numLabel][3]);
  76.             areaTexture.add(sprite);
  77.             numLabel++;
  78.         }
  79.        
  80.         boxAnima = new Rectangle(xInizio, yInizio, sizeX, sizeY);
  81.         areAnima = new JPanel() {
  82.             @Override
  83.             protected void paintComponent(java.awt.Graphics g) {
  84.                 super.paintComponent(g);
  85.                 java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
  86.                
  87.                 g2.setColor(Color.WHITE);
  88.                 g2.setStroke(new java.awt.BasicStroke(5));
  89.                 if (boxAnima != null) {
  90.                     g2.draw(boxAnima);
  91.                 }
  92.             }
  93.         };
  94.        
  95.         areAnima.setBounds(0, 268, 880, 201);
  96.         areAnima.setOpaque(false);
  97.         areAnima.setBackground(new Color(0, 0, 0, 0));
  98.        
  99.        
  100.         areaVita = new JPanel();
  101.         areaVita.setBounds(0, 603, 880, 67);
  102.         areaVita.setBackground(new Color(0, 0, 0, 0));
  103.         areaScelte = new JPanel();
  104.         areaScelte.setBounds(0, 469, 880, 134);
  105.         areaScelte.setBackground(new Color(0, 0, 0, 0));
  106.         areaScelte.setLayout(null);
  107.         fightButton = new JButton(new ImageIcon("Texture/fight_button.png"));
  108.         fightButton.setBounds(15, 40, 150, 52);
  109.        
  110.         actButton = new JButton(new ImageIcon("Texture/act_button.png"));
  111.         actButton.setBounds(210, 40, 150, 52);
  112.        
  113.         itemButton = new JButton(new ImageIcon("Texture/item_button.png"));
  114.         itemButton.setBounds(405, 40, 150, 52);
  115.        
  116.         mercyButton = new JButton(new ImageIcon("Texture/mercy_button.png"));
  117.         mercyButton.setBounds(600, 40, 150, 52);
  118.        
  119.         areaScelte.add(fightButton);
  120.         areaScelte.add(actButton);
  121.         areaScelte.add(itemButton);
  122.         areaScelte.add(mercyButton);
  123.        
  124.    
  125.        
  126.         areAttacco = new JPanel();
  127.         areAttacco.setBounds(0, 261, 880, 200);
  128.         areAttacco.setBackground(new Color(0, 0, 0, 0));
  129.      
  130.        
  131.         JLabel sfondo = new JLabel(new ImageIcon("Texture/inizio.png"));
  132.         sfondo.setBounds(0, 0, 880, 671);
  133.        
  134.        
  135.  
  136.         this.add(areaTexture);
  137.         this.add(areaVita);
  138.         this.add(areaScelte);
  139.         this.add(areAnima);
  140.         this.add(sfondo);
  141.  
  142.         this.setComponentZOrder(sfondo, this.getComponentCount() - 1);
  143.         this.setComponentZOrder(areaScelte, 1);
  144.        
  145.         Main.mappaClasse.setVisible(false);
  146.         Main.finestra.add(this);
  147.         this.setVisible(true);
  148.         Main.finestra.revalidate();
  149.         Main.finestra.repaint();
  150.     }
  151.  
  152.     void raccogliOcchi(Sprite occhio, int numLabel) { //This method "captures" the eyes founded in "creaAmbiente"
  153.         if("occhio_su".equals(occhio.getTag()) && this.occhioSu == null) {
  154.             this.occhioSu = occhio;
  155.         }else if("occhio_su".equals(occhio.getTag()) && this.occhioSu != null) {
  156.             this.occhioSu2 = occhio;
  157.         } else if("occhio_giù".equals(occhio.getTag()) && this.occhioGiù == null) {
  158.             this.occhioGiù = occhio;
  159.         } else if("occhio_giù".equals(occhio.getTag()) && this.occhioGiù != null) {
  160.             this.occhioGiù2 = occhio;
  161.         }else if("occhio_destra".equals(occhio.getTag()) && this.occhioDestra == null) {
  162.             this.occhioDestra = occhio;
  163.         }else if("occhio_destra".equals(occhio.getTag()) && this.occhioDestra != null) {
  164.             this.occhioDestra2 = occhio;
  165.         }else if("occhio_sinistra".equals(occhio.getTag()) && this.occhioSinistra == null) {
  166.             this.occhioSinistra = occhio;
  167.         }else if("occhio_sinistra".equals(occhio.getTag()) && this.occhioSinistra != null) {
  168.             this.occhioSinistra2 = occhio;
  169.         }
  170.        
  171.         if(this.occhioSu != null && this.occhioGiù != null && this.occhioDestra != null && this.occhioSinistra != null && !this.animOcchi1) {
  172.             this.animOcchi1 = true;
  173.             Sprite[] occhi = {this.occhioSu, this.occhioGiù, this.occhioDestra, this.occhioSinistra};
  174.             animOcchi(numLabel, occhi);
  175.         }
  176.         if(this.occhioSu2 != null && this.occhioGiù2 != null && this.occhioDestra2 != null && this.occhioSinistra2 != null && !this.animOcchi2) {
  177.             this.animOcchi2 = true;
  178.             Sprite[] occhi = {this.occhioSu2, this.occhioGiù2, this.occhioDestra2, this.occhioSinistra2};
  179.             animOcchi(numLabel, occhi);
  180.         }
  181.     }
  182.    
  183.    
  184.     void animOcchi(int numLabel, Sprite[] occhi) { //This method makes the eyes animation (in italian "occhio" means eye)
  185.         Icon[] frameIcone = new Icon[4];
  186.         frameIcone[0] = occhi[0].getIcon();
  187.         frameIcone[1] = occhi[1].getIcon();
  188.         frameIcone[2] = occhi[2].getIcon();
  189.         frameIcone[3] = occhi[3].getIcon();
  190.  
  191.         occhi[0].setBounds(e.posSprites[numLabel][0], e.posSprites[numLabel][1], e.posSprites[numLabel][2], e.posSprites[numLabel][3]);
  192.         this.areaTexture.add(occhi[0]);
  193.  
  194.         int[] numOcchio = {0};
  195.         Timer timer = new Timer(500, e -> {
  196.             if (numOcchio[0] < 3) {
  197.                 numOcchio[0]++;
  198.             } else {
  199.                 numOcchio[0] = 0;
  200.             }
  201.             occhi[0].setIcon(frameIcone[numOcchio[0]]);
  202.         });
  203.  
  204.         timer.setRepeats(true);
  205.         timer.start();
  206.     }
  207.    
  208.     void raccoglInversioni(Sprite inversione, int numLabel) {
  209.         String tagInv = inversione.getTag().substring(inversione.getTag().indexOf("inverti_") + 8);
  210.  
  211.         if (tempInversione1 != null && tagInv.equals(tempInversione1.getTag())) {
  212.             invertiSprites(inversione, tempInversione1, numLabel);
  213.             tempInversione1 = null;
  214.         } else if (tempInversione2 != null && tagInv.equals(tempInversione2.getTag())) {
  215.             invertiSprites(inversione, tempInversione2, numLabel);
  216.             tempInversione2 = null;
  217.         } else if (tempInversione3 != null && tagInv.equals(tempInversione3.getTag())) {
  218.             invertiSprites(inversione, tempInversione3, numLabel);
  219.             tempInversione3 = null;
  220.         } else if (tempInversione4 != null && tagInv.equals(tempInversione4.getTag())) {
  221.             invertiSprites(inversione, tempInversione4, numLabel);
  222.             tempInversione4 = null;
  223.         } else {
  224.             if (tempInversione1 == null) { tempInversione1 = inversione; tempInversione1.setTag(tagInv); }
  225.             else if (tempInversione2 == null) { tempInversione2 = inversione; tempInversione2.setTag(tagInv); }
  226.             else if (tempInversione3 == null) { tempInversione3 = inversione; tempInversione3.setTag(tagInv); }
  227.             else if (tempInversione4 == null) { tempInversione4 = inversione; tempInversione4.setTag(tagInv); }
  228.         }
  229.     }
  230.    
  231.     void invertiSprites(Sprite inv1, Sprite inv2, int numLabel) { //"invertiSprites" in italian means invertSprites
  232.       /*
  233.        * This method alternates the images of the two sprites with the same tag,
  234.        * commenting this method solves the problem, although the mop obviously does not appear
  235.        *
  236.        */
  237.         inv1.setBounds(e.posSprites[numLabel][0], e.posSprites[numLabel][1], e.posSprites[numLabel][2], e.posSprites[numLabel][3]);
  238.         this.areaTexture.add(inv1);
  239.  
  240.         Icon img1 = inv1.getIcon();
  241.         Icon img2 = inv2.getIcon();
  242.  
  243.         boolean[] fase = {false};
  244.         Timer timer = new Timer(500, e -> {
  245.             fase[0] = !fase[0];
  246.             inv1.setIcon(fase[0] ? img2 : img1);
  247.             this.areaTexture.repaint();
  248.         });
  249.        
  250.         timer.setRepeats(true);
  251.         timer.start();
  252.     }
  253. }
  254.  
  255.  
  256.  
  257.  
Tags: Code
Advertisement
Add Comment
Please, Sign In to add comment