Ejemplo n.º 1
1
 public MapBuilder(String name, File toLoad, File toSave, String tileDir) {
   super(name);
   currTileImg = null;
   currTileLoc = "";
   try {
     System.out.println(tileDir);
     currTileImg = new ImageIcon(getTile(tileDir, 0, 0, DISPLAY_SCALE));
     currTileLoc = "0_0";
   } catch (IOException e) {
     System.out.println("Generating current tile failed.");
     System.out.println(e);
     System.exit(0);
   }
   currTileDisplay = new JLabel(new ImageIcon(scaleImage(currTileImg.getImage(), 2)));
   this.input = toLoad;
   output = toSave;
   this.tileDir = tileDir;
   if (toLoad != null) {
     try {
       backEnd = loadMap(toLoad);
     } catch (FileNotFoundException e) {
       System.err.println("Could not find input file.");
       System.exit(0);
     }
   } else {
     backEnd = emptyMap(DEFAULT_WIDTH, DEFAULT_HEIGHT);
   }
   mapWidth = backEnd.getWidth();
   mapHeight = backEnd.getHeight();
 }
Ejemplo n.º 2
0
 public void mouseClicked(MouseEvent e) {
   Tile t = (Tile) e.getSource();
   ImageIcon temp = (ImageIcon) t.getIcon();
   currTileImg = new ImageIcon(scaleImage(temp.getImage(), DISPLAY_SCALE));
   currTileDisplay.setIcon(new ImageIcon(scaleImage(temp.getImage(), DISPLAY_SCALE * 2)));
   currTileLoc = t.getSource();
 }
Ejemplo n.º 3
0
  /** ************** Display result of processed Image *********** */
  void imageResultDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgIcon = new ImageIcon();
    imgIcon.setImage(img_temp);
    lbl_res.setIcon(imgIcon);
  }
Ejemplo n.º 4
0
  /** ****************** Display Gray Scale version of image opened *************** */
  void grayImageDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgI = new ImageIcon();
    imgI.setImage(img_temp);
    lbl_gray.setIcon(imgI);
  }
Ejemplo n.º 5
0
  /**
   * Creates a new GMap object based on a base directory specified in the constructure.
   *
   * @param cache - Base directory to search for cached image folders.
   */
  public GMap(String cache) {
    // data source
    this.gDataSourceMap = new GDataSourceMap(cache + "/map_cache");
    this.gDataSourceSatellite = new GDataSourceSatellite(cache + "/sat_cache");
    // this.gDataSourceOverlay = new GDataSourceOverlay(cache+"/overlay_cache");
    this.gDataSourceHybrid = new GDataSourceHybrid(cache + "/hybrid_cache", gDataSourceSatellite);

    // build default image
    defaultImage = getDefaultImage(GDataSource.sourceSize.width, GDataSource.sourceSize.height);

    // init gdraw draw object
    this.gDraw = new GDraw();

    // mode
    this.mode = MAP_MODE;

    // icon
    ImageIcon loadImage = new ImageIcon("images/google.png");
    googleImage = loadImage.getImage();
  }
Ejemplo n.º 6
0
  public void drawBuffer() {
    Graphics2D b = buffer.createGraphics(); // DrawPanel
    Graphics2D pl_b = buffer.createGraphics();
    Graphics2D pl_c = buffer.createGraphics();
    rkt = buffer.createGraphics();
    AffineTransform rkt_aff = new AffineTransform();
    Graphics2D envi[] = new Graphics2D[amountEnv];
    AffineTransform enviTrans[] = new AffineTransform[amountEnv];

    b.setColor(Color.BLACK);
    b.fillRect(0, 0, w, h);

    // #if (Default)
    // @
    // #elif (Blue_White)
    // @        	ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeiss1.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Blue_White_Green)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeissGruen.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Purple_White)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgLilaWeiss.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Glass)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundglass05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Lava)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlava01.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Limba)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlimba.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Old)
    ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundoldpnt01.gif");
    img_bg = ii_bg.getImage();
    b.drawImage(img_bg, w, w, this);
    // #elif (Ov_Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundov_paper.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundpaper05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Univ)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrunduniv01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water_2)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater05.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #endif

    b.setColor(Color.gray);
    b.fillRect(0, 0, w, 25); // oben
    b.fillRect(0, h - 50, w, 25); // unten
    b.fillRect(0, 0, 25, h); // links
    b.fillRect(w - 35, 0, 30, h); // rechts
    b.setColor(Color.WHITE);

    // rocket
    // #if (tar)
    // #if (Rectangle)
    // @               if (current_Player.isRocket()){
    // @                   rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                   rkt.setTransform(rkt_aff);
    // @                   System.out.println("Rok X:"+sch.getX()+" Rok Y:"+sch.getY());
    // @                   rkt.drawRect(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket 4Eck
    // #endif
    // #if (Oval)
    // @               if (current_Player.isRocket()){
    // @                   b.drawOval(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket Oval
    // #endif
    // #if (aa31)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/aa31.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null, (int)sch.getX(), (int)sch.getY());
    // @                        //rkt.drawImage(rocketFire, null, (int)current_Player.getX(),
    // (int)current_Player.getY());
    // @                    } catch (IOException e) {
    // @                    }
    // @                 }
    // #endif
    // #if (Portal)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/portal.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #if (Nino)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/nino.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #endif

    for (int i = 0; i <= amountEnv - 1; i++) {
      envi[i] = buffer.createGraphics();
      enviTrans[i] = new AffineTransform();
      envi[i].setTransform(enviTrans[i]);
      envi[i].drawImage(env[i].getImg(), env[i].getX(), env[i].getY(), this);
    }

    for (int i = 0; i < 8; i++) {
      if (powerUps[i].isAktiv()) {
        b.setColor(powerUps[i].getCol());
        b.drawImage(powerUps[i].getImg(), powerUps[i].getX(), powerUps[i].getY(), this);
      }
    }

    b.setColor(Color.WHITE);
    b.drawString("BP: " + current_Player.getBp(), 10, 20);
    b.drawString("TP P1/P2: " + player_1.getTp() + " / " + player_2.getTp(), 100, 20);

    if (current_Player.getSch().getEnd_X() != 0 && current_Player.getSch().getEnd_Y() != 0) {
      b.setColor(Color.YELLOW);
      b.drawLine(
          (int) current_Player.getSch().getStart_X(),
          (int) current_Player.getSch().getStart_Y(),
          (int) current_Player.getSch().getEnd_X(),
          (int) current_Player.getSch().getEnd_Y());
      b.setColor(Color.WHITE);
      for (int i = 0; i < current_Player.getSch().getArImg().length; i++) {
        if (current_Player.getSch().getArImg()[i] != null && current_Player.getSch().isIsActive()) {
          b.drawImage(
              current_Player.getSch().getArImg()[i],
              (int) current_Player.getSch().getEnd_X()
                  - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
              (int) current_Player.getSch().getEnd_Y()
                  - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
              (int)
                  (current_Player.getSch().getArImg()[i].getWidth(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              (int)
                  (current_Player.getSch().getArImg()[i].getHeight(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              this);
          if (timeCounter == 75) {
            System.out.println("----------------------><---------------------");
            if (player_1
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_1.setTp(player_1.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P1 <---------------------");
            }
            if (player_2
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_2.setTp(player_2.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P2 <---------------------");
            }
          }
        }
        if (timeCounter >= 150) {
          timeCounter = 0;
          current_Player.getSch().setIsActive(false);
          current_Player.getSch().setEnd_X(0);
          current_Player.getSch().setEnd_Y(0);
        }
        if (current_Player.getSch().isIsActive()) timeCounter += 1;
        System.out.println("timecounter: " + timeCounter);
      }
    }

    if (player_1.getTp() <= 0) b.drawString("SPIELER 2 HAT GEWONNEN !", w / 2, h / 2);
    if (player_2.getTp() <= 0) b.drawString("SPIELER 1 HAT GEWONNEN !", w / 2, h / 2);

    current_Player.setStop(false);
    b.setColor(Color.red);

    AffineTransform a = new AffineTransform();
    a.rotate(
        current_Player.getDegree(),
        current_Player.getX() + current_Player.getWidth() / 2,
        current_Player.getY() + current_Player.getHeight() / 2);
    ((Graphics2D) pl_b).setTransform(a);
    pl_b.drawImage(
        current_Player.getImg(), (int) current_Player.getX(), (int) current_Player.getY(), this);
    System.out.println(
        "P1 X:" + (int) current_Player.getX() + " P1 Y:" + (int) current_Player.getY());
    System.out.println("P1 W:" + current_Player.getWidth() + " P1 H:" + current_Player.getHeight());
    AffineTransform a2 = new AffineTransform();
    a2.rotate(
        other_Player.getDegree(),
        other_Player.getX() + other_Player.getWidth() / 2,
        other_Player.getY() + other_Player.getHeight() / 2);
    ((Graphics2D) pl_c).setTransform(a2);
    pl_c.drawImage(
        other_Player.getImg(), (int) other_Player.getX(), (int) other_Player.getY(), this);

    if (current_Player.isCollision() == true) {
      current_Player.setStop(true);
      if (timecount > 10) {
        b.setColor(Color.WHITE);
        b.drawString("C O L L I S I O N !", (int) w / 2 - 50, (int) h / 2);
        timecount--;
      } else {
        timecount = 0;
        current_Player.setBp(0);
        current_Player.setX(300);
        current_Player.setY(100);
        current_Player.getSch().setEnd_X(1);
        current_Player.getSch().setEnd_Y(1);
        current_Player.getSch().setStart_X(1);
        current_Player.getSch().setStart_Y(1);
      }
      b.dispose();
    }
  }