コード例 #1
0
  public void createField(Map map, Vector2D startVector, int terrainType, int size) {
    Vector2D position = startVector;

    for (int i = 0; i < size; i++) {
      position = position.add(Vector2D.create(-1 + Random.getInt(3), -1 + Random.getInt(3)));

      Cell cellProtected = map.getCellProtected(position.getXAsInt(), position.getYAsInt());
      if (!cellProtected.getMapCoordinate().equals(position)) {
        position = cellProtected.getMapCoordinate();
      }

      putTerrainOnCell(map, position.getXAsInt(), position.getYAsInt(), terrainType);
    }
  }
コード例 #2
0
  public void createCircularField(Map map, Vector2D centerPosition, int terrainType, int size) {
    if (size < 1) return;

    int TILE_SIZE = 32;
    float halfATile = TILE_SIZE / 2;
    // convert to absolute pixel coordinates
    Vector2D asPixelsCentered =
        map.getCellCoordinatesInAbsolutePixels(
                centerPosition.getXAsInt(), centerPosition.getYAsInt())
            .add(Vector2D.create(halfATile, halfATile));

    double centerX = asPixelsCentered.getX();
    double centerY = asPixelsCentered.getY();

    for (int rangeStep = 0; rangeStep < size; rangeStep++) { // range 'steps'

      for (int degrees = 0; degrees < 360; degrees++) {

        // calculate as if we would draw a circle and remember the coordinates
        float rangeInPixels = (rangeStep * TILE_SIZE);
        double circleX = (centerX + (Trigonometry.cos[degrees] * rangeInPixels));
        double circleY = (centerY + (Trigonometry.sin[degrees] * rangeInPixels));

        // convert back the pixel coordinates back to a cell
        Cell cell =
            map.getCellByAbsoluteMapCoordinates(
                Coordinate.create((int) Math.ceil(circleX), (int) Math.ceil(circleY)));

        putTerrainOnCell(map, cell.getX(), cell.getY(), terrainType);
      }
    }
  }