public void draw(Graphics2D g) {

    // draw tilemap
    tileMap.draw(g);

    // draw player
    player.draw(g);

    // draw diamonds
    for (Diamond d : diamonds) {
      d.draw(g);
    }

    // draw sparkles
    for (Sparkle s : sparkles) {
      s.draw(g);
    }

    // draw items
    for (Item i : items) {
      i.draw(g);
    }

    // draw hud
    hud.draw(g);

    // draw transition boxes
    g.setColor(java.awt.Color.BLACK);
    for (int i = 0; i < boxes.size(); i++) {
      g.fill(boxes.get(i));
    }
  }
  public void update() {

    // check keys
    handleInput();

    // check events
    if (eventStart) eventStart();
    if (eventFinish) eventFinish();

    if (player.numDiamonds() == player.getTotalDiamonds()) {
      eventFinish = blockInput = true;
    }

    // update camera
    int oldxs = xsector;
    int oldys = ysector;
    xsector = player.getx() / sectorSize;
    ysector = player.gety() / sectorSize;
    tileMap.setPosition(-xsector * sectorSize, -ysector * sectorSize);
    tileMap.update();

    if (oldxs != xsector || oldys != ysector) {
      JukeBox.play("mapmove");
    }

    if (tileMap.isMoving()) return;

    // update player
    player.update();

    // update diamonds
    for (int i = 0; i < diamonds.size(); i++) {

      Diamond d = diamonds.get(i);
      d.update();

      // player collects diamond
      if (player.intersects(d)) {

        // remove from list
        diamonds.remove(i);
        i--;

        // increment amount of collected diamonds
        player.collectedDiamond();

        // play collect sound
        JukeBox.play("collect");

        // add new sparkle
        Sparkle s = new Sparkle(tileMap);
        s.setPosition(d.getx(), d.gety());
        sparkles.add(s);

        // make any changes to tile map
        ArrayList<int[]> ali = d.getChanges();
        for (int[] j : ali) {
          tileMap.setTile(j[0], j[1], j[2]);
        }
        if (ali.size() != 0) {
          JukeBox.play("tilechange");
        }
      }
    }

    // update sparkles
    for (int i = 0; i < sparkles.size(); i++) {
      Sparkle s = sparkles.get(i);
      s.update();
      if (s.shouldRemove()) {
        sparkles.remove(i);
        i--;
      }
    }

    // update items
    for (int i = 0; i < items.size(); i++) {
      Item item = items.get(i);
      if (player.intersects(item)) {
        items.remove(i);
        i--;
        item.collected(player);
        JukeBox.play("collect");
        Sparkle s = new Sparkle(tileMap);
        s.setPosition(item.getx(), item.gety());
        sparkles.add(s);
      }
    }
  }