コード例 #1
0
ファイル: Event.java プロジェクト: poros/Arianna
 /** @return the pois */
 public Map<String, PointOfInterest> getPois() {
   if (this.pois == null || this.pois.isEmpty()) {
     Map<String, PointOfInterest> pois = new HashMap<String, PointOfInterest>();
     for (MapLevel mapLevel : this.getLevels().values()) {
       for (NavigationNode navigationNode : mapLevel.getNavigationNodes().values()) {
         pois.putAll(navigationNode.getPois());
       }
     }
     this.pois = pois;
   }
   return this.pois;
 }
コード例 #2
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Updates a specific square on this level.
   *
   * @param x
   * @param y
   */
  public void updateSquare(byte x, byte y) {
    Graphics2D surface = currentScreen.createGraphics();
    int mapHeight = ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT);

    surface.drawImage(
        createSquare(mapLevel.getMapSquare(x, y)),
        null,
        x * ImageBank.FEATUREWIDTH,
        mapHeight - (y * ImageBank.FEATUREHEIGHT));

    surface.dispose();
  }
コード例 #3
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Sets the maps current viewport view.
   *
   * @param playerCoords Player's coordinates
   */
  public void setCurrentView(Coord playerCoords) {
    int x = (playerCoords.getX() * ImageBank.FEATUREWIDTH) - 75;
    int y =
        ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT)
            - ((playerCoords.getY() * ImageBank.FEATUREHEIGHT) + 50);

    viewPort.setViewPosition(new Point(x, y));
  }
コード例 #4
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Updates the arrow.
   *
   * @param x
   * @param y
   * @param dir
   */
  public void updateArrow(Coord coords) {
    Graphics2D surface = currentScreen.createGraphics();
    Polygon arrow = getArrow(coords);
    int mapHeight = ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT);

    // Redraw this square.
    surface.drawImage(
        createSquare(mapLevel.getMapSquare(coords)),
        null,
        coords.getX() * ImageBank.FEATUREWIDTH,
        mapHeight - (coords.getY() * ImageBank.FEATUREHEIGHT));

    // Overlay the arrow.
    surface.setColor(Color.RED);
    surface.fillPolygon(arrow);
    surface.setColor(Color.WHITE);
    surface.drawPolygon(arrow);

    surface.dispose();
  }
コード例 #5
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Updates the whole map image.
   *
   * @param playerCoords Coordinates of the player.
   */
  private void updateMapImage(Coord playerCoords) {
    currentScreen =
        new BufferedImage(
            mapLevel.getWidth() * ImageBank.FEATUREWIDTH,
            mapLevel.getHeight() * ImageBank.FEATUREHEIGHT,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D surface = currentScreen.createGraphics();
    int mapHeight = ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT);

    surface.setColor(Color.GRAY);
    surface.fillRect(0, 0, currentScreen.getWidth(), currentScreen.getHeight());

    for (byte x = 0; x < mapLevel.getWidth(); x++) {
      for (byte y = 0; y < mapLevel.getHeight(); y++) {
        if (mapLevel.getMapSquare(x, y).isVisited()) {
          surface.drawImage(
              createSquare(mapLevel.getMapSquare(x, y)),
              null,
              x * ImageBank.FEATUREWIDTH,
              mapHeight - (y * ImageBank.FEATUREHEIGHT));
        }
      }
    }

    // draw player arrow.
    if (playerCoords.getZ() == mapLevel.getLevel()) {
      Polygon arrow = getArrow(playerCoords);
      surface.setColor(Color.RED);
      surface.fillPolygon(arrow);
      surface.setColor(Color.WHITE);
      surface.drawPolygon(arrow);
    }

    setPreferredSize(
        new Dimension(
            mapLevel.getWidth() * ImageBank.FEATUREWIDTH,
            mapLevel.getHeight() * ImageBank.FEATUREHEIGHT));
    revalidate();
  }
コード例 #6
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Updates the map's viewport's viewing rectangle
   *
   * @param playerCoords Player's coordinates
   */
  public void updateCurrentView(Coord playerCoords) {
    int x = (playerCoords.getX() * ImageBank.FEATUREWIDTH) - (viewPort.getWidth() >>> 1);
    int y =
        ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT)
            - ((playerCoords.getY() * ImageBank.FEATUREHEIGHT) + (viewPort.getHeight() >>> 1));

    if (x < 0) x = 0;
    if (x > (currentScreen.getWidth() - viewPort.getWidth()))
      x = (currentScreen.getWidth() - viewPort.getWidth());
    if (y < 0) y = 0;
    if (y > (currentScreen.getHeight() - viewPort.getHeight()))
      y = (currentScreen.getHeight() - viewPort.getHeight());

    viewPort.setViewPosition(new Point(x, y));
  }
コード例 #7
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Creates a polygon with the correct corners representing the player's arrow
   *
   * @param playerCoords Player's coordinates
   * @return Polygon The player arrow.
   */
  private Polygon getArrow(Coord playerCoords) {
    Polygon arrow = new Polygon();
    int mapHeight = 5 + ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT);
    int left = (playerCoords.getX() * ImageBank.FEATUREWIDTH);
    int top = mapHeight - ((playerCoords.getY() * ImageBank.FEATUREHEIGHT) + 5);

    switch (playerCoords.getDirection()) {
      case North:
        arrow.addPoint(left + 7, top);
        arrow.addPoint(left + 14, top + 7);
        arrow.addPoint(left + 10, top + 7);
        arrow.addPoint(left + 10, top + 14);
        arrow.addPoint(left + 4, top + 14);
        arrow.addPoint(left + 4, top + 7);
        arrow.addPoint(left, top + 7);
        break;
      case East:
        arrow.addPoint(left + 14, top + 7);
        arrow.addPoint(left + 7, top + 14);
        arrow.addPoint(left + 7, top + 10);
        arrow.addPoint(left, top + 10);
        arrow.addPoint(left, top + 4);
        arrow.addPoint(left + 7, top + 4);
        arrow.addPoint(left + 7, top);
        break;
      case South:
        arrow.addPoint(left + 7, top + 14);
        arrow.addPoint(left + 14, top + 7);
        arrow.addPoint(left + 10, top + 7);
        arrow.addPoint(left + 10, top);
        arrow.addPoint(left + 4, top);
        arrow.addPoint(left + 4, top + 7);
        arrow.addPoint(left, top + 7);
        break;
      case West:
        arrow.addPoint(left, top + 7);
        arrow.addPoint(left + 7, top + 14);
        arrow.addPoint(left + 7, top + 10);
        arrow.addPoint(left + 14, top + 10);
        arrow.addPoint(left + 14, top + 4);
        arrow.addPoint(left + 7, top + 4);
        arrow.addPoint(left + 7, top);
        break;
    }

    return arrow;
  }
コード例 #8
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
 /**
  * Retrieves the depth of this map.
  *
  * @return byte
  */
 public byte getLevel() {
   return mapLevel.getLevel();
 }
コード例 #9
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Updates another square and repaints.
   *
   * @param coords Coord to update.
   */
  public void updateNonPlayerSquare(Coord coords) {
    if (coords.getZ() != mapLevel.getLevel()) return; // This square is not on this level...

    updateSquare(coords.getX(), coords.getY());
    repaint();
  }
コード例 #10
0
ファイル: MapPane.java プロジェクト: ajunkala/mordor-clone
  /**
   * Update the square the player is based on the passed coordinates. Repaints
   *
   * @param coords Coord of player
   */
  public void updatePlayerSquare(Coord coords) {
    if (coords.getZ() != mapLevel.getLevel()) return; // This square is not on this level...

    updateArrow(coords);
    repaint();
  }