Ejemplo n.º 1
0
  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));
    }
  }
Ejemplo n.º 2
0
  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);
      }
    }
  }
Ejemplo n.º 3
0
  private void populateDiamonds() {

    Diamond d;

    d = new Diamond(tileMap);
    d.setTilePosition(20, 20);
    d.addChange(new int[] {23, 19, 1});
    d.addChange(new int[] {23, 20, 1});
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(12, 36);
    d.addChange(new int[] {31, 17, 1});
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(28, 4);
    d.addChange(new int[] {27, 7, 1});
    d.addChange(new int[] {28, 7, 1});
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(4, 34);
    d.addChange(new int[] {31, 21, 1});
    diamonds.add(d);

    d = new Diamond(tileMap);
    d.setTilePosition(28, 19);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(35, 26);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(38, 36);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(27, 28);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(20, 30);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(14, 25);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(4, 21);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(9, 14);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(4, 3);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(20, 14);
    diamonds.add(d);
    d = new Diamond(tileMap);
    d.setTilePosition(13, 20);
    diamonds.add(d);
  }