Beispiel #1
1
  void setVerticalWall(WallData wall, int level, boolean undo) {
    if (wall != null && wall.houseWall) {
      if (!(isFlat() || map.getTile(this, -1, 0).isFlat())) {
        return;
      }
    }

    final EntityData entityData;
    if (wall != null && wall.houseWall) {
      entityData = new EntityData(level, EntityType.VWALL);
    } else if (wall != null) {
      entityData = new EntityData(level, EntityType.VFENCE);
    } else {
      entityData = null;
    }

    final EntityData wallEntity = new EntityData(level, EntityType.VWALL);
    final EntityData fenceEntity = new EntityData(level, EntityType.VFENCE);
    final Wall currentWall = (Wall) entities.get(wallEntity);
    final Wall currentFence = (Wall) entities.get(fenceEntity);

    boolean reversed;
    if (wall != null && wall.houseWall) {
      if (Globals.autoReverseWall) {
        reversed =
            getTileContent(level) == null && map.getTile(this, -1, 0).getTileContent(level) != null;
        if (reversed == false) {
          reversed = Globals.reverseWall;
        }
      } else {
        reversed = Globals.reverseWall;
      }
    } else {
      reversed = false;
    }

    if (!(new Wall(wall, reversed).equals(entities.get(entityData)))) {
      Tile oldTile = new Tile(this);
      if (wall != null) {
        entities.put(entityData, new Wall(wall, reversed));
        if (wall.houseWall
            && !(wall.arch && currentFence != null && currentFence.data.archBuildable)) {
          entities.remove(fenceEntity);
        } else if (!wall.houseWall
            && !(wall.archBuildable && currentWall != null && currentWall.data.arch)) {
          entities.remove(wallEntity);
        }
      } else {
        entities.remove(wallEntity);
        entities.remove(fenceEntity);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Beispiel #2
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);
  }
Beispiel #3
0
 public Materials getMaterials(boolean withRight, boolean withTop) {
   Materials materials = new Materials();
   entities
       .values()
       .stream()
       .forEach(
           (entity) -> {
             materials.put(entity.getMaterials());
           });
   if (withRight) {
     for (int i = 0; i < Constants.FLOORS_LIMIT; i++) {
       Wall wall = map.getTile(this, 1, 0).getVerticalWall(i);
       Wall fence = map.getTile(this, 1, 0).getVerticalFence(i);
       if (wall != null) {
         materials.put(wall.getMaterials());
       }
       if (fence != null) {
         materials.put(fence.getMaterials());
       }
     }
   }
   if (withTop) {
     for (int i = 0; i < Constants.FLOORS_LIMIT; i++) {
       Wall wall = map.getTile(this, 0, 1).getHorizontalWall(i);
       Wall fence = map.getTile(this, 0, 1).getHorizontalFence(i);
       if (wall != null) {
         materials.put(wall.getMaterials());
       }
       if (fence != null) {
         materials.put(fence.getMaterials());
       }
     }
   }
   return materials;
 }
Beispiel #4
0
 public boolean isPassable(TileBorder border) {
   switch (border) {
     case SOUTH:
       return getHorizontalWall(0) == null;
     case NORTH:
       return map.getTile(this, 0, 1) != null
           && map.getTile(this, 0, 1).getHorizontalWall(0) == null;
     case WEST:
       return getVerticalWall(0) == null;
     case EAST:
       return map.getTile(this, 1, 0) != null
           && map.getTile(this, 1, 0).getVerticalWall(0) == null;
     default:
       return false;
   }
 }
Beispiel #5
0
 public boolean isFlat() {
   return map.getTile(this, 1, 1) != null
       && getHeight() == map.getTile(this, 1, 1).getHeight()
       && map.getTile(this, 1, 0) != null
       && getHeight() == map.getTile(this, 1, 0).getHeight()
       && map.getTile(this, 0, 1) != null
       && getHeight() == map.getTile(this, 0, 1).getHeight();
 }
  /**
   * Builds a blank display. Eventually I'll have to add loading from a map, though right now it
   * builds the map itself. I should separate that out.
   */
  public JComponent buildDisplay() {
    JPanel holder = new JPanel(new GridBagLayout());
    map = holder;

    // holder.setLayout(new GridLayout(mapHeight,mapWidth));
    // holder.setPreferredSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    // 									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // holder.setMaximumSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    //  									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // backEnd = emptyMap(mapWidth, mapHeight);

    GridBagConstraints gbc = new GridBagConstraints();

    // for(int i = 0; i < mapHeight; i++){
    // 	List<Tile> tList = new ArrayList<Tile>();
    // 	gbc.gridy = i;
    // 	for(int j = 0; j < mapWidth; j++){
    // 		gbc.gridx = j;
    // 		Tile t = new Tile(currTileImg, "Test", 0, 0, mov,"none",true, "0_0");
    // 		tList.add(t);
    // 		//t.setMargin(new Insets(0,0,0,0));
    // 		t.setMaximumSize(new Dimension(TILE_SIZE*DISPLAY_SCALE,TILE_SIZE*DISPLAY_SCALE));
    // 		t.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		//tile.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		t.addMouseListener(new MapButtonListener());
    // 		holder.add(t,gbc);

    // 	}
    // 	backEnd.addRow(tList);
    // }

    for (int i = 0; i < mapHeight; i++) {
      gbc.gridy = i;
      for (int j = 0; j < mapWidth; j++) {
        gbc.gridx = j;
        holder.add(backEnd.getTile(j, i), gbc);
      }
    }
    // gbc.gridy = 0;
    // gbc.gridx = mapWidth;
    // gbc.gridheight = GridBagConstraints.REMAINDER;
    // gbc.weightx = 1;
    // gbc.weighty = 1;
    // gbc.fill = GridBagConstraints.BOTH;
    // holder.add(new JPanel(), gbc);
    // gbc.gridx = 0;
    // gbc.gridy = mapHeight;
    // gbc.gridheight = 1;
    // gbc.gridwidth = GridBagConstraints.REMAINDER;
    // holder.add(new JPanel(), gbc);
    // System.out.println(backEnd);

    // Container panel to prevent stretching
    JPanel outer = new JPanel();
    outer.add(holder);

    // BoxLayout ensures that maxSize is honored
    // JPanel displaySizeRegulator = new JPanel();
    // displaySizeRegulator.setLayout(new BoxLayout(displaySizeRegulator, BoxLayout.X_AXIS));

    JScrollPane displayScroll =
        new JScrollPane(
            outer,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    mapScroll = displayScroll;

    // displaySizeRegulator.add(displayScroll);
    // displayRefresher = displaySizeRegulator;
    return displayScroll;
  }