Guest User

Untitled

a guest
Aug 8th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1.     @Override
  2.     public void renderMap(Player p, MapCanvas c) {
  3.         GameMap gamemap = getGameMap();
  4.         if (gamemap == null)
  5.             return;
  6.         Location l = p.getLocation();
  7.         int x = l.getBlockX() - gamemap.getX();
  8.         int y = l.getBlockZ() - gamemap.getY();
  9.         double rad = Math.toRadians(180 - l.getYaw());
  10.         BufferedImage img = RendererTask.rotatedMap(gamemap.getImage(), x * 2, y * 2, rad);
  11.         Graphics2D g = (Graphics2D) img.getGraphics();
  12.         g.setPaint(java.awt.Color.WHITE);
  13.         GameTeam team = getTeam(p);
  14.         team.getPlayers().stream()
  15.                 .filter(teammate -> teammate != p && !getSpectatorsClone().contains(teammate)).forEach(teammate -> {
  16.                     Location el = teammate.getLocation();
  17.                     MapPosition mp = MapPosition.calculatedPos(l, el, rad);
  18.                     g.fillRect(mp.x - 2, mp.y - 2, 4, 4);
  19.                 });
  20.         g.setPaint(java.awt.Color.GREEN);
  21.         g.fillRect(62, 62, 4, 4);
  22.         if (team.getRole == Role.TERRORIST) {
  23.             if (bomb != null) {
  24.                 Location b = bomb.getLocation();
  25.                 if (b != null) {
  26.                     MapPosition mp = MapPosition.calculatedPos(l, b, rad);
  27.                     g.setPaint(java.awt.Color.RED);
  28.                     g.fillRect(mp.x - 2, mp.y - 2, 4, 4);
  29.                 }
  30.             }
  31.         }
  32.         c.drawImage(0, 0, img);
  33.     }
  34.  
  35.     // RenderTask.rotatedMap
  36.     public static BufferedImage rotatedMap(BufferedImage map, int x, int y, double rad) {
  37.         BufferedImage i = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
  38.         if (map == null)
  39.             return i;
  40.         Graphics2D ig2 = (Graphics2D) i.getGraphics();
  41.         AffineTransform at = new AffineTransform();
  42.         at.translate(64 - x, 64 - y);
  43.         at.rotate(rad, x, y);
  44.         ig2.drawImage(map, at, null);
  45.         return i;
  46.     }
  47.    
  48.     //MapPosition.calculatedPos
  49.     public static MapPosition calculatedPos(Location l, Location el, double rad) {
  50.         int xe = (el.getBlockX() - l.getBlockX()) * 2;
  51.         int ye = (el.getBlockZ() - l.getBlockZ()) * 2;
  52.         int xe1 = (int) (xe * Math.cos(rad) - ye * Math.sin(rad));
  53.         int ye1 = (int) (ye * Math.cos(rad) + xe * Math.sin(rad));
  54.         if (xe1 < -63)
  55.             xe1 = -63;
  56.         if (xe1 > 63)
  57.             xe1 = 63;
  58.         if (ye1 < -63)
  59.             ye1 = -63;
  60.         if (ye1 > 63)
  61.             ye1 = 63;
  62.         xe1 += 64;
  63.         ye1 += 64;
  64.         return new MapPosition(xe1, ye1);
  65.     }
Add Comment
Please, Sign In to add comment