Exemplo n.º 1
0
  @Override
  public void renderGameLoop(Graphics2D g) {
    // TODO Auto-generated method stub
    super.renderGameLoop(g);

    Point levelRenderOffset =
        new Point(
            (int) Math.round((this.getCanvasWidth() / 16) * 0.5),
            (int) Math.round((this.getCanvasHeight() / 16) * 0.5));

    level.highlightTile = new Point(Math.round(player.origin.x), Math.round(player.origin.y));
    level.render(g, player.origin.x - levelRenderOffset.x, player.origin.y - levelRenderOffset.y);

    for (Projectile p : projectiles) {
      Point2f renderPoint =
          new Point2f(
              (p.origin.x - player.origin.x) * 16 - levelRenderOffset.x + 8,
              (p.origin.y - player.origin.y) * 16 - levelRenderOffset.y + 8);
      g.drawImage(
          p.getImage(),
          (this.getCanvasWidth() / 2) + Math.round(renderPoint.x),
          (this.getCanvasHeight() / 2) + Math.round(renderPoint.y),
          null);
    }

    player.render(g, (this.getCanvasWidth() / 2) - 8, (this.getCanvasHeight() / 2));

    for (MobAI mob : mobs) {
      Point2f renderPoint =
          new Point2f(
              (mob.origin.x - player.origin.x) * 16 - levelRenderOffset.x,
              (mob.origin.y - player.origin.y) * 16 - levelRenderOffset.y + 8);
      mob.render(
          g,
          (this.getCanvasWidth() / 2) + Math.round(renderPoint.x),
          (this.getCanvasHeight() / 2) + Math.round(renderPoint.y));

      if (mob.health < mob.maxHealth)
        drawHealth(
            g,
            mob.health / (float) mob.maxHealth,
            (this.getCanvasWidth() / 2) + Math.round(renderPoint.x),
            (this.getCanvasHeight() / 2) + Math.round(renderPoint.y));
    }
  }