Esempio n. 1
0
  // ----------------------------------------------------------------------
  protected void baseInternalLoad(Element xml) {
    name = xml.get("Name", name);

    size = xml.getInt("Size", size);
    if (size < 1) {
      size = 1;
    }

    tile = new GameTile[size][size];

    quality = xml.getInt("Quality", quality);

    Element spriteElement = xml.getChildByName("Sprite");
    if (spriteElement != null) {
      sprite = AssetManager.loadSprite(xml.getChildByName("Sprite"));
    }

    if (sprite != null) {
      sprite.size[0] = size;
      sprite.size[1] = size;
    }

    Element raisedSpriteElement = xml.getChildByName("TilingSprite");
    if (raisedSpriteElement != null) {
      tilingSprite = TilingSprite.load(raisedSpriteElement);
    }

    if (tilingSprite != null) {
      // for (Sprite sprite : tilingSprite.sprites)
      // {
      //	sprite.size = size;
      // }
    }

    Element lightElement = xml.getChildByName("Light");
    if (lightElement != null) {
      light = Roguelike.Lights.Light.load(lightElement);
    }

    Element statElement = xml.getChildByName("Statistics");
    if (statElement != null) {
      Statistic.load(statElement, statistics);
      HP = getMaxHP();

      statistics.put(Statistic.WALK, 1);
      // statistics.put( Statistic.ENTITY, 1 );
    }

    Element inventoryElement = xml.getChildByName("Inventory");
    if (inventoryElement != null) {
      inventory.load(inventoryElement);
    }

    Element immuneElement = xml.getChildByName("Immune");
    if (immuneElement != null) {
      immune = immuneElement.getText().toLowerCase().split(",");
    }

    canTakeDamage = xml.getBoolean("CanTakeDamage", canTakeDamage);

    UID = getClass().getSimpleName() + " " + name + ": ID " + hashCode();
  }
Esempio n. 2
0
  private void loadLayer(TiledMap map, Element element) {
    if (element.getName().equals("Layer")) {
      String id = element.getAttribute("Id");
      String visible = element.getAttribute("Visible");

      Element dimensions = element.getChildByName("Dimensions");
      String layerSize = dimensions.getAttribute("LayerSize");
      String tileSize = dimensions.getAttribute("TileSize");

      String[] layerSizeParts = layerSize.split(" x ");
      int layerSizeX = Integer.parseInt(layerSizeParts[0]);
      int layerSizeY = Integer.parseInt(layerSizeParts[1]);

      String[] tileSizeParts = tileSize.split(" x ");
      int tileSizeX = Integer.parseInt(tileSizeParts[0]);
      int tileSizeY = Integer.parseInt(tileSizeParts[1]);

      TiledMapTileLayer layer = new TiledMapTileLayer(layerSizeX, layerSizeY, tileSizeX, tileSizeY);
      Element tileArray = element.getChildByName("TileArray");
      Array<Element> rows = tileArray.getChildrenByName("Row");
      TiledMapTileSets tilesets = map.getTileSets();
      TiledMapTileSet currentTileSet = null;
      int firstgid = 0;
      int x, y;
      for (int row = 0, rowCount = rows.size; row < rowCount; row++) {
        Element currentRow = rows.get(row);
        y = rowCount - 1 - row;
        x = 0;
        for (int child = 0, childCount = currentRow.getChildCount(); child < childCount; child++) {
          Element currentChild = currentRow.getChild(child);
          String name = currentChild.getName();
          if (name.equals("TileSheet")) {
            currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
            firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
          } else if (name.equals("Null")) {
            x += currentChild.getIntAttribute("Count");
          } else if (name.equals("Static")) {
            Cell cell = new Cell();
            cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
            layer.setCell(x++, y, cell);
          } else if (name.equals("Animated")) {
            // Create an AnimatedTile
            int interval = currentChild.getInt("Interval");
            Element frames = currentChild.getChildByName("Frames");
            Array<StaticTiledMapTile> frameTiles = new Array<StaticTiledMapTile>();
            for (int frameChild = 0, frameChildCount = frames.getChildCount();
                frameChild < frameChildCount;
                frameChild++) {
              Element frame = frames.getChild(frameChild);
              String frameName = frame.getName();
              if (frameName.equals("TileSheet")) {
                currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref"));
                firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
              } else if (frameName.equals("Static")) {
                frameTiles.add(
                    (StaticTiledMapTile)
                        currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
              }
            }
            Cell cell = new Cell();
            cell.setTile(new AnimatedTiledMapTile(interval / 1000f, frameTiles));
            layer.setCell(x++, y, cell); // TODO: Reuse existing animated tiles
          }
        }
      }
      map.getLayers().add(layer);
    }
  }