Exemplo n.º 1
0
  @Override
  public void applyToWorld(World w, int leftBoundary, int rightBoundary) {
    int surf = 0, x = leftBoundary + (rightBoundary - leftBoundary) / 2;
    // find surface
    while (w.getTerrainAt(x, surf) == World.AIR) {
      surf++;
    }

    makeSpawnShop(w, x, surf);
    int center = leftBoundary + (rightBoundary - leftBoundary) / 2;

    for (int i = center - 25; i < center + 25; i++) {
      for (int y = surf - 10; y > 0; y--) {
        w.setTerrainAt(i, y, World.AIR);
      }
    }

    for (int i = leftBoundary; i < rightBoundary; i++) {
      for (int y = (int) (0.2F * w.getHeight()); y < w.getHeight() * mineDepth; y++) {
        if (w.getTerrainAt(i, y) == World.AIR && w.getSeed().nextDouble() <= 0.1) {
          w.setTerrainAt(i, y, World.TORCH);
        }
      }
    }
  }
  // this does not work properly. (exploration is not exhaustive, essentially a raycast-to-hit)
  private static boolean[][] checkCluster(
      World w, int scrapType, int x, int y, boolean[][] okayBlocks) {
    ArrayList<int[]> currentBlocks = new ArrayList<int[]>(0);
    currentBlocks.add(new int[] {x, y});
    int blockTally = 0;
    int talliger = 0;

    while (blockTally < threshold && currentBlocks.size() > talliger) {
      int[] block = currentBlocks.get(talliger);
      if (w.getTerrainAt(block[0], block[1]) != scrapType) { // if it's not the scrap "limiter"
        blockTally++; // count this block

        // add blocks exploring out from center
        if (block[0] >= x && block[0] < w.getWidth() - 1) {
          currentBlocks.add(new int[] {block[0] + 1, block[1]});
        }
        if (block[0] <= x && block[0] > 0) {
          currentBlocks.add(new int[] {block[0] - 1, block[1]});
        }
        if (block[1] >= y && block[1] < w.getHeight() - 1) {
          currentBlocks.add(new int[] {block[0], block[1] + 1});
        }
        if (block[1] <= y && block[1] > 0) {
          currentBlocks.add(new int[] {block[0], block[1] - 1});
        }
      }
      okayBlocks[block[0]][block[1]] =
          true; // say that this block has been checked out as part of a cluster
      talliger++; // remove checked block
    }

    if (blockTally < threshold) { // if it was too small
      // System.out.println("cluster too small");
      for (int i = 0; i < talliger; i++) {
        w.setTerrainAt(
            currentBlocks.get(i)[0], currentBlocks.get(i)[1], scrapType); // replace it with air
      }
    } else {
      // System.out.println("cluster checks out");
    }

    return okayBlocks;
  }