Exemple #1
0
  public void applyPhysics(World world) {
    final Iterator<MapLayer> layerIterator = tiledMap.getLayers().iterator();
    while (layerIterator.hasNext()) {
      final MapLayer mapLayer = layerIterator.next();
      if (mapLayer instanceof TiledMapTileLayer) {
        final TiledMapTileLayer tiledLayer = (TiledMapTileLayer) mapLayer;
        final int width = tiledLayer.getWidth();
        final int height = tiledLayer.getHeight();
        for (int y = 0; y < height; y++) {
          for (int x = 0; x < width; x++) {
            final TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
            if (cell == null) {
              continue;
            }
            final boolean dirt = cell.getTile().getProperties().containsKey("dirt");
            final boolean noWall = cell.getTile().getProperties().containsKey("nowall");
            if (!noWall) {
              addBody(world, x + offset.x, y + offset.y, dirt);
            }
          }
        }
      }
    }

    for (String portalName : portals.keySet()) {
      final Vector2 portalPosition = portals.get(portalName);
      addPortalBody(world, portalName, portalPosition);
    }

    final Vector2 finish = getTriggerPoint("finish");
    if (finish != null) {
      addFinish(world, finish);
    }
  }
Exemple #2
0
 public Map<String, Vector2> getTriggerStartWith(String name) {
   final HashMap<String, Vector2> triggerObjects = new HashMap<String, Vector2>();
   final Iterator<MapObject> mapObjectIterator =
       tiledMap.getLayers().get("trigger").getObjects().iterator();
   final int tileWidth = (Integer) tiledMap.getProperties().get("tilewidth");
   final int tileHeight = (Integer) tiledMap.getProperties().get("tileheight");
   while (mapObjectIterator.hasNext()) {
     final MapObject mapObject = mapObjectIterator.next();
     if (mapObject != null
         && mapObject.getName() != null
         && mapObject.getName().startsWith(name)) {
       triggerObjects.put(
           mapObject.getName(),
           new Vector2(
               (Float) mapObject.getProperties().get("x") / tileWidth,
               (Float) mapObject.getProperties().get("y") / tileHeight));
     }
   }
   return triggerObjects;
 }
Exemple #3
0
 public void draw(Batch batch) {
   batch.begin();
   final Iterator<MapLayer> layerIterator = tiledMap.getLayers().iterator();
   while (layerIterator.hasNext()) {
     final MapLayer mapLayer = layerIterator.next();
     if (mapLayer instanceof TiledMapTileLayer) {
       final TiledMapTileLayer tiledLayer = (TiledMapTileLayer) mapLayer;
       final int width = tiledLayer.getWidth();
       final int height = tiledLayer.getHeight();
       for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
           final TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
           if (cell == null) {
             continue;
           }
           final TextureRegion textureRegion = cell.getTile().getTextureRegion();
           batch.draw(textureRegion, x + offset.x, y + offset.y, 1, 1);
         }
       }
     }
   }
   batch.end();
 }