Example #1
1
  /** Runs the frame */
  public void runFrame() {
    boolean secondMove =
        ((cursorMoveTimer >= frameSkip && cursorMoveTimer < 2 * frameSkip - 1) && !fast);
    if (!isMoving() && !secondMove) {
      if (cuLeft > 0) x--;

      if (cuRight > 0) x++;

      if (cuUp > 0) y--;

      if (cuDown > 0) y++;

      if (x < 0) x = 0;
      if (x > map.getWidth() - 1) x = map.getWidth() - 1;
      if (y < 0) y = 0;
      if (y > map.getHeight() - 1) y = map.getHeight() - 1;

      if (fast) {
        frameSkip = fastFS;
        speed = fastSpeed;
      } else {
        frameSkip = slowFS;
        speed = slowSpeed;
      }
    }

    moveToDest();
  }
Example #2
1
  public void arrive(Thing t) {

    Map map = getMap();

    if (map == null) throw new Error("EdgePortal Error - no map specified");

    int tx = -1;
    int ty = -1;
    int i = 0;

    while (tx == -1) {
      switch (RPG.d(5)) {
        case 1:
          if ((side & NORTH) > 0) {
            ty = 0;
            tx = RPG.r(map.getWidth());
          }
          ;
          break;
        case 2:
          if ((side & SOUTH) > 0) {
            ty = map.getHeight() - 1;
            tx = RPG.r(map.getWidth());
          }
          ;
          break;
        case 3:
          if ((side & WEST) > 0) {
            tx = 0;
            ty = RPG.r(map.getHeight());
          }
          ;
          break;
        case 4:
          if ((side & EAST) > 0) {
            tx = map.getWidth() - 1;
            ty = RPG.r(map.getHeight());
          }
          ;
          break;
        case 5:
          if ((side & ZONE) > 0) {
            tx = RPG.r(map.getWidth());
            ty = RPG.r(map.getHeight());
          }
          ;
          break;
      }

      i++;
      if (i > 5000)
        throw new Error("EdgePortal Error - unable to find space to add " + t.getName());

      if ((tx >= 0) && (map.isBlocked(tx, ty))) tx = -1;
    }
    ;

    t.moveTo(map, tx, ty);
  }
Example #3
1
  public float getHeight(final float xPart, final float yPart) {
    final float xPartRev = 1f - xPart;
    final float yPartRev = 1f - yPart;

    final float h00 = height;
    final float h10 = x != map.getWidth() ? map.getTile(this, 1, 0).height : 0;
    final float h01 = y != map.getHeight() ? map.getTile(this, 0, 1).height : 0;
    final float h11 =
        (x != map.getWidth() && y != map.getHeight()) ? map.getTile(this, 1, 1).height : 0;

    final float x0 = (h00 * xPartRev + h10 * xPart);
    final float x1 = (h01 * xPartRev + h11 * xPart);

    return (x0 * yPartRev + x1 * yPart);
  }
 public void fillMapWithTerrain(Map map, int terrainType) {
   for (int x = 1; x <= map.getWidth(); x++) {
     for (int y = 1; y <= map.getHeight(); y++) {
       putTerrainOnCell(map, x, y, terrainType);
     }
   }
 }
Example #5
1
  /**
   * 描画処理
   *
   * @param 描画オブジェクト
   */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // 背景を黒で塗りつぶす
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, getWidth(), getHeight());

    // X方向のオフセットを計算
    int offsetX = MainPanel.WIDTH / 2 - (int) player.getX();
    // マップの端ではスクロールしないようにする
    offsetX = Math.min(offsetX, 0);
    offsetX = Math.max(offsetX, MainPanel.WIDTH - map.getWidth());

    // Y方向のオフセットを計算
    int offsetY = MainPanel.HEIGHT / 2 - (int) player.getY();
    // マップの端ではスクロールしないようにする
    offsetY = Math.min(offsetY, 0);
    offsetY = Math.max(offsetY, MainPanel.HEIGHT - map.getHeight());

    // マップを描画
    map.draw(g, offsetX, offsetY);

    // プレイヤーを描画
    player.draw(g, offsetX, offsetY);

    // スプライトを描画
    // マップにいるスプライトを取得
    LinkedList sprites = map.getSprites();
    Iterator iterator = sprites.iterator();
    while (iterator.hasNext()) {
      Sprite sprite = (Sprite) iterator.next();
      sprite.draw(g, offsetX, offsetY);
    }
  }
Example #6
1
 public MapBuilder(String name, File toLoad, File toSave, String tileDir) {
   super(name);
   currTileImg = null;
   currTileLoc = "";
   try {
     System.out.println(tileDir);
     currTileImg = new ImageIcon(getTile(tileDir, 0, 0, DISPLAY_SCALE));
     currTileLoc = "0_0";
   } catch (IOException e) {
     System.out.println("Generating current tile failed.");
     System.out.println(e);
     System.exit(0);
   }
   currTileDisplay = new JLabel(new ImageIcon(scaleImage(currTileImg.getImage(), 2)));
   this.input = toLoad;
   output = toSave;
   this.tileDir = tileDir;
   if (toLoad != null) {
     try {
       backEnd = loadMap(toLoad);
     } catch (FileNotFoundException e) {
       System.err.println("Could not find input file.");
       System.exit(0);
     }
   } else {
     backEnd = emptyMap(DEFAULT_WIDTH, DEFAULT_HEIGHT);
   }
   mapWidth = backEnd.getWidth();
   mapHeight = backEnd.getHeight();
 }
 private void fillMap(Map seed, Map map) {
   if (seed != null) {
     for (int i = 0; i < map.getWidth(); i++) {
       for (int j = 0; j < map.getHeight(); j++) {
         map.write(i, j, seed.read(i, j));
       }
     }
   }
 }
Example #8
0
  @Override
  public void start(Stage primaryStage) {

    // generated layout to be converted to GUI
    File sampleLayoutXMLFile =
        new File("MapLayout.xml"); // added to see functionality with xml file
    Map layout = new Map(sampleLayoutXMLFile); // <==
    // Map layout = new Map();

    // main container for GUI: has areas for top/bottom/left/right/center
    BorderPane root = new BorderPane();

    // container for map GUI
    GridPane map = new GridPane();
    map.setPadding(new Insets(MAP_PADDING));
    map.setHgap(CELL_GAP);
    map.setVgap(CELL_GAP);

    // array of cells to be added to map GUI
    StackPane cells[][] = new StackPane[layout.getWidth()][layout.getHeight()];

    for (int row = 0; row < layout.getHeight(); row++) {
      for (int col = 0; col < layout.getWidth(); col++) {
        // create the cell's appearance
        cells[row][col] = buildCell(layout.getCell(row, col));
        // this is the correct way to have it
        // https://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html#add(javafx.scene.Node, int, int)
        map.add(cells[row][col], row, col);
      }
    }

    root.setCenter(map);

    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Clean Sweep Vacuum");
    primaryStage.show();
  }
  public void smooth(Map map) {
    System.out.println("Smoothing all cells");
    for (int x = 1; x <= map.getWidth(); x++) {
      for (int y = 1; y <= map.getHeight(); y++) {
        Cell cell = map.getCell(x, y);
        final Terrain terrain = cell.getTerrain();

        TerrainFacing facing =
            getFacing(
                terrain.isSame(cell.getCellAbove().getTerrain()),
                terrain.isSame(cell.getCellRight().getTerrain()),
                terrain.isSame(cell.getCellBeneath().getTerrain()),
                terrain.isSame(cell.getCellLeft().getTerrain()));

        terrain.setFacing(facing);
      }
    }
  }
  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);
    }
  }