示例#1
0
  void renderer(Graphics2D g2d) {
    height = window.getHeight() - 20;
    width = window.getWidth();

    lastTime = curTime;
    curTime = System.currentTimeMillis();
    totalTime += curTime - lastTime;
    if (totalTime > 1000) {
      totalTime -= 1000;
      fps = frames;
      frames = 0;
    }
    ++frames;

    delta = 16.0 / (curTime - lastTime);
    if (delta < 0) delta = 0;

    g2d.setColor(Color.white);
    if (removeMode) g2d.fill(new Rectangle(0, 0, width, height));

    if (eventHandeler(g2d)) {
      renderBackground(g2d);
      return;
    }

    Graphics2D map = (Graphics2D) g2d.create();
    playerHandeler();
    xOffset = -player.body.getCenterX() + width / 2;
    yOffset = -player.body.getCenterY() + height / 2;

    if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX();
    else if (-xOffset > bounds.getBounds2D().getMaxX() - width)
      xOffset = -bounds.getBounds2D().getMaxX() + width;

    if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY();
    else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3)
      yOffset = -bounds.getBounds2D().getMaxY() + height - 3;

    map.translate(xOffset, yOffset);

    renderBackground(map);
    itemHandeler(map);
    enemieHandeler();
    characterHandeler(map);

    map.setColor(Color.black);
    map.draw(bounds);

    renderUI(g2d);
  }