Advertisement
teleias

Untitled

May 13th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //A diamond shape
  2.     public void draw(Graphics2D g)
  3.     {
  4.         g.setColor(getColor());
  5.         g.transform(myTranslation);
  6.         g.transform(myRotation);
  7.         //This shape is a square.. I just rotated it.
  8.         int[] xs = new int[]{width/2, 0, -width/2, 0};
  9.         int[] ys = new int[]{0, height/2, 0, -height/2};
  10.         g.fillPolygon(xs, ys, 4);
  11.         try {
  12.             g.transform(myRotation.createInverse());
  13.             g.transform(myTranslation.createInverse());
  14.         } catch (NoninvertibleTransformException e) {
  15.             // TODO Auto-generated catch block
  16.             e.printStackTrace();
  17.         }
  18.     }
  19.  
  20. //A square shape
  21.     public void draw(Graphics2D g)
  22.     {
  23.         g.setColor(getColor());
  24.         g.transform(myTranslation);
  25.         g.transform(myRotation);
  26.         g.drawRect((int)(0), (int)(0), 1, 1);
  27.         try {
  28.             g.transform(myRotation.createInverse());
  29.             g.transform(myTranslation.createInverse());
  30.         } catch (NoninvertibleTransformException e) {
  31.             // TODO Auto-generated catch block
  32.             e.printStackTrace();
  33.         }
  34.     }
  35.  
  36. //Inside mapview
  37. public void paintComponent(Graphics g) {
  38.         super.paintComponent(g);
  39.         Graphics2D g2d = (Graphics2D)g;
  40.         AffineTransform saveAT = g2d.getTransform();
  41.        
  42.         g2d.translate(0, this.getHeight());
  43.         g2d.scale(1, -1);
  44.         g2d.scale(5, 5);
  45.         //If it's not blank, go ahead and paint each element in our lists.
  46.         if(fieldSquares != null && !fieldSquares.isEmpty())
  47.             for(FieldSquare fs : fieldSquares)
  48.             {
  49.                 fs.draw(g2d);
  50.             }
  51.         if(gameObjects != null && !gameObjects.isEmpty())
  52.             for(GameObject go : gameObjects)
  53.             {
  54.                 go.draw(g2d);
  55.             }
  56.     g2d.setTransform(saveAT);
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement