コード例 #1
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);
      }
    }
  }
コード例 #2
0
  private void fillMapWithRandomTerrainTypeFields(Map map) {
    System.out.println("Putting terrain on map");
    fillMapWithTerrain(map, DuneTerrain.TERRAIN_SAND);

    createCircularField(map, Vector2D.create(0, 0), DuneTerrain.TERRAIN_ROCK, 20);
    createCircularField(
        map, Vector2D.create(map.getWidth(), map.getHeight()), DuneTerrain.TERRAIN_ROCK, 20);

    for (int f = 0; f < 5; f++) {
      Vector2D randomVec = Vector2D.random(15, 45, 15, 45);
      createCircularField(map, randomVec, DuneTerrain.TERRAIN_SPICE, 6);
      createField(map, randomVec, DuneTerrain.TERRAIN_SPICE, 200);
      createField(map, randomVec, DuneTerrain.TERRAIN_SPICE_HILL, 50);
    }

    for (int f = 0; f < 5; f++) {
      Vector2D randomVec = Vector2D.random(15, 45, 15, 45);
      createCircularField(map, randomVec, DuneTerrain.TERRAIN_ROCK, 6);
      createField(map, randomVec, DuneTerrain.TERRAIN_ROCK, 100);
      //            createField(map, randomVec, DuneTerrain.TERRAIN_MOUNTAIN, 25);
    }
  }
コード例 #3
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);
    }
  }