コード例 #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);
        }
      }
    }
  }
コード例 #2
0
  // 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;
  }
コード例 #3
0
  @Override
  public void applyToWorld(World w) {
    System.out.println("Cleaning Scraps");

    boolean[][] okayBlocks = new boolean[w.getWidth()][w.getHeight()];
    for (int x = 0; x < w.getWidth(); x++) {
      for (int y = 0; y < w.getHeight(); y++) {
        okayBlocks[x][y] = false;
      }
    }
    for (int x = 0; x < w.getWidth(); x++) {
      for (int y = 0; y < w.getHeight(); y++) {
        if (!okayBlocks[x][y]) {
          okayBlocks = checkCluster(w, scrapType, x, y, okayBlocks);
        }
      }
    }
  }
コード例 #4
0
  private void makeSpawnShop(World w, int x, int y) {

    int O = World.AIR;
    int W = World.WOOD; // TODO wood
    int S = World.STONE;
    int D = World.DIRT;
    int I = -1;

    int[][] shop = {
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, W, W, W, W, W, W, W, W, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, W, O, O, O, O, O, O, O, O, W, O,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O
      },
      {
        I, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, W, O, O, O, O, O, O, O, O, O, O, W,
        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, I
      },
      {
        I, I, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, W, O, O, O, O, O, O, O, O, O, O, O, O,
        W, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, I, I
      },
      {
        I, I, I, I, I, O, O, O, O, O, O, O, O, O, O, O, O, O, W, O, O, O, O, O, O, O, O, O, O, O, O,
        W, O, O, O, O, O, O, O, O, O, O, O, O, O, I, I, I, I, I
      },
      {
        I, I, I, I, I, I, I, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, O, O, O, I, I, I, I, I, I, I
      },
      {
        I, I, I, I, I, I, I, I, I, I, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
        O, O, O, O, O, O, O, O, O, I, I, I, I, I, I, I, I, I, I
      },
      {
        I, I, I, I, I, I, I, I, I, I, I, I, O, O, O, O, O, O, W, W, W, W, W, W, W, W, W, W, W, W, W,
        W, O, O, O, O, O, O, I, I, I, I, I, I, I, I, I, I, I, I
      },
      {
        I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, S, S, S, S, S, S, S, S, S, S, S, S, S,
        S, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I
      },
      {
        I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, S, S, S, S, S, S, S, S, S, S, S, S, S,
        S, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I
      },
    };

    w.makeStructure(shop, x - shop[0].length / 2, y - shop.length + 3);
  }