예제 #1
0
 public void update(double slowdown, double arrival) {
   freeway.update(slowdown, arrival);
   if (buffer == null) {
     xsize = size().width;
     ysize = size().height;
     buffer = createImage(xsize, ysize);
   }
   Graphics bg = buffer.getGraphics();
   freeway.paint(bg, row, XDOTDIST, DOTSIZE);
   if (row < ysize - 2 * DOTSIZE + 1) row += DOTSIZE;
   else {
     bg.copyArea(0, DOTSIZE, xsize, ysize - DOTSIZE, 0, -DOTSIZE);
     bg.clearRect(0, ysize - DOTSIZE, xsize, DOTSIZE);
   }
   bg.dispose();
   repaint();
 }
예제 #2
0
    public void paint(Graphics g) {
      g = this.startPaint(g);
      int width = this.getSize().width;
      int height = this.getSize().height;
      g.clearRect(0, 0, width, height);
      int cell_size, xstart, ystart;
      double panel_aspect_ratio = (double) width / height;
      double grid_aspect_ratio = (double) grid[0].length / grid.length;
      if (panel_aspect_ratio > grid_aspect_ratio) {
        cell_size = (int) ((double) height / grid.length + 0.5);
        xstart = (int) (width / 2 - (grid[0].length / 2.0 * cell_size + 0.5));
        ystart = 0;
      } else {
        cell_size = (int) ((double) width / grid[0].length + 0.5);
        xstart = 0;
        ystart = (int) (height / 2 - (grid.length / 2.0 * cell_size + 0.5));
      }

      if (paint_background) {
        g.setColor(
            BACKGROUND_COLORS[
                (num_rows_deleted / DELETED_ROWS_PER_LEVEL) % BACKGROUND_COLORS.length]);
        g.fillRect(xstart, ystart, COLUMNS * cell_size, ROWS * cell_size);
      }

      for (int i = 0; i < grid.length; i++) {
        for (int j = 0; j < grid[0].length; j++) {
          if (grid[i][j] != EMPTY) {
            g.setColor(PIECE_COLORS[grid[i][j]]);
            int x = xstart + j * cell_size;
            int y = ystart + i * cell_size;
            g.fill3DRect(x, y, cell_size, cell_size, true);
          }
        }
      }
      this.endPaint();
    }
  public void paint(Graphics g) {
    // int numDoors=0;
    int rX = player.getRelativeX();
    int rY = player.getRelativeY();
    boolean notInBuilding = true;
    bufferGraphics.clearRect(0, 0, dim.width, dim.width);
    bufferGraphics.setColor(Color.WHITE);
    r2.setLocation(20 + rX, 20 + rY);

    // Iterator<Objects>  iterator1 = entities.iterator();//size is the last index, therefore it
    // starts at the end
    // while(iterator1.hasNext()){
    // iterator1.next().update(rX, rY);
    // bufferGraphics.drawImage(iterator1.next().image, iterator1.next().blockX+rX,
    // iterator1.next().blockX+rY, null);
    // }
    for (int x = 0; x < buildings.size(); x++) {
      buildings.get(x).update(rX, rY);
      player.onDoor(player.r, buildings.get(x).door);
      player.collideOn(player.r, buildings.get(x));
      if (player.inHouse(player.r, buildings.get(x).inside)) {
        notInBuilding = false;
      }
      // if(notInBuilding){
      // bufferGraphics.drawImage(buildings.get(x).image,
      // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null);
      // }else{
      // bufferGraphics.drawImage(buildings.get(x).innerImage,
      // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null);
      // }

      // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y,
      // entities.get(x).bounds.width, entities.get(x).bounds.height);
    }

    bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 20));
    // String m1 = new Boolean(player.canMove('w')).toString();
    bufferGraphics.drawString(message, 0, 170);
    // bufferGraphics.fillRect(r2.x, r2.y, r2.width, r2.height);
    // player.collideOn(player.r, r2);
    // ***Image log1 = new ImageIcon(getClass().getResource("logTest.png")).getImage();
    // ***bufferGraphics.drawImage(log1, (int)r2.getX(), (int)r2.getY(), null);
    // bufferGraphics.drawLine((int)player.N.getX1(), (int)player.N.getY1(), (int)player.N.getX2(),
    // (int)player.N.getY2());
    // bufferGraphics.drawLine((int)player.E.getX1(), (int)player.E.getY1(), (int)player.E.getX2(),
    // (int)player.E.getY2());
    // bufferGraphics.drawLine((int)player.S.getX1(), (int)player.S.getY1(), (int)player.S.getX2(),
    // (int)player.S.getY2());
    // bufferGraphics.drawLine((int)player.W.getX1(), (int)player.W.getY1(), (int)player.W.getX2(),
    // (int)player.W.getY2());
    // bufferGraphics.setColor(Color.RED);
    // bufferGraphics.drawLine((int)player.NI.getX1(), (int)player.NI.getY1(),
    // (int)player.NI.getX2(), (int)player.NI.getY2());
    // bufferGraphics.drawLine((int)player.EI.getX1(), (int)player.EI.getY1(),
    // (int)player.EI.getX2(), (int)player.EI.getY2());
    // bufferGraphics.drawLine((int)player.SI.getX1(), (int)player.SI.getY1(),
    // (int)player.SI.getX2(), (int)player.SI.getY2());
    // bufferGraphics.drawLine((int)player.WI.getX1(), (int)player.WI.getY1(),
    // (int)player.WI.getX2(), (int)player.WI.getY2());
    if (notInBuilding) {
      Image thebg = new ImageIcon(getClass().getResource("grassbackingdev.png")).getImage();
      bufferGraphics.drawImage(thebg, 0 + rX, 0 + rY, null);
    }

    player.update();
    int setX = Math.abs(player.relativeX);
    int setY = Math.abs(player.relativeY);
    if (player.relativeX > 0) {
      setX = -setX;
    }
    if (player.relativeY > 0) {
      setY = -setY;
    }

    if (notInBuilding) {
      for (int x = 0; x < entities.size(); x++) {
        entities.get(x).update(rX, rY);
        bufferGraphics.drawImage(
            entities.get(x).image, entities.get(x).blockX + rX, entities.get(x).blockY + rY, null);
        player.collideOn(player.r, entities.get(x));
        if (entities.get(x).health <= 0) {
          if (entities.get(x).material == "Wood") wood += entities.get(x).matsReturn;
          if (entities.get(x).material == "Stone") stone += entities.get(x).matsReturn;
          entities.remove(x);
        }
        // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y,
        // entities.get(x).bounds.width, entities.get(x).bounds.height);
      }
    }
    for (int x = 0; x < buildings.size(); x++) {
      if (notInBuilding) {
        bufferGraphics.drawImage(
            buildings.get(x).image,
            buildings.get(x).blockX + rX,
            buildings.get(x).blockY + rY,
            null);
      } else {
        bufferGraphics.drawImage(
            buildings.get(x).innerImage,
            buildings.get(x).blockX + rX,
            buildings.get(x).blockY + rY,
            null);
      }
    }
    if (notInBuilding) {
      for (int x = 0; x < npcArray.size(); x++) {

        for (int e = 0; e < entities.size(); e++) {
          npcArray.get(x).detectEntities(entities.get(e));
          if (entities.get(e).health <= 0) {
            entities.remove(e);
          }
        }
        npcArray.get(x).update(rX, rY, setX + 92, setY + 82);
        bufferGraphics.drawImage(
            npcArray.get(x).graphic, npcArray.get(x).npcX + rX, npcArray.get(x).npcY + rY, null);
        if (npcArray.get(x).isDead()) {
          npcArray.remove(x);
        } else if (npcArray.get(x).hitBox.intersects(player.r)) {
          player.health -= 25;
          npcArray.remove(x);
        }
      }
    }
    for (int x = 0; x < playerAttack.size(); x++) {
      playerAttack.get(x).update(rX, rY);
      bufferGraphics.drawImage(
          playerAttack.get(x).graphic,
          playerAttack.get(x).currentX + rX,
          playerAttack.get(x).currentY + rY,
          null);
      for (int y = 0; y < npcArray.size(); y++) {
        if (playerAttack.get(x).hitBox.intersects(npcArray.get(y).hitBox)) {
          npcArray.get(y).health -= 25;
          playerAttack.get(x).hasHit = true;
        }
      }
      if (playerAttack.get(x).isDead()) {
        playerAttack.remove(x);
      }
    }

    player.notOnDoor = true;
    if (player.moving) {
      bufferGraphics.drawImage(
          player.getImage().getImage(), player.getCharx(), player.getChary(), null); // TODO
    } else {
      bufferGraphics.drawImage(player.getIdle(), player.getCharx(), player.getChary(), null);
    }
    if (Ghosting) {
      if (player.face == 1) {
        bufferGraphics.drawImage(player.getResource(resource), 104, 87, null); // EAST
      }
      if (player.face == 2) {
        bufferGraphics.drawImage(player.getResource(resource), 94, 106, null); // SOUTH*94,106
      }
      if (player.face == 3) {
        bufferGraphics.drawImage(player.getResource(resource), 84, 87, null); // WEST84,87
      }
      if (player.face == 4) {
        bufferGraphics.drawImage(player.getResource(resource), 94, 75, null); // NORTH94,75
      }
    }
    if (player.health <= 0) {
      bufferGraphics.drawString("You are dead", 10, 90);
      stop();
    }
    bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 9));
    bufferGraphics.setColor(new Color(160, 82, 45));
    bufferGraphics.fillRect(0, 2, 8, 8);
    bufferGraphics.setColor(new Color(105, 105, 105));
    bufferGraphics.fillRect(0, 12, 8, 8);
    bufferGraphics.drawImage(statusBar, 0, 22, null);
    bufferGraphics.setColor(Color.WHITE);
    bufferGraphics.drawString(String.format("%d", wood), 18, 10);
    bufferGraphics.drawString(String.format("%d", stone), 18, 20);
    bufferGraphics.drawString(String.format("%d", player.health), 18, 30);
    // bufferGraphics.fillRect((int)player.r.getX(), (int)player.r.getY(),
    // (int)player.r.getWidth(),(int)player.r.getHeight());
    // bufferGraphics.fillRect(player.r.x, player.r.x, player.r.width, player.r.height);
    g.drawImage(offScreen, 0, 0, this);
    // if(drawConsole){
    // message = String.format("wood: %d", wood);
    // }

  }
예제 #4
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
 public void update(Graphics g) {
   if (img == null) g.clearRect(0, 0, getSize().width, getSize().height);
   paintComponent(g);
 }