/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.processors.loaders;
import transientlibs.processors.misc.Detonator;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.World;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.maps.container.TiledMapGDXContainer;
/**
*
** @author kibertoad
*/
public class MapAssetLoader {
private Body playerBody;
private MapProperties tileProps;
public void loadMapCollisionInfo (TiledMapGDXContainer map){
Log.info("Have map: "+(map != null));
Log.info("Have map2: "+(map.getTiledMapGDX() != null));
Log.info("Have map3: "+(map.getTiledMapGDX().gdxMap != null));
map.world = new World(new Vector2(), true);
TiledMapTileLayer collisionLayer = (TiledMapTileLayer) map.getTiledMapGDX().gdxMap.getLayers().get(Detonator.INSTANCE.obstaclesLayerCode);
if(collisionLayer != null){
for(int y = 0; y < collisionLayer.getHeight(); y++){
for(int x = 0; x < collisionLayer.getWidth(); x++){
String collision = "false";
TiledMapTileLayer.Cell tile = collisionLayer.getCell(x, y);
if(tile != null){
collision = "true";
tileProps = tile.getTile().getProperties();
if (tileProps.containsKey("iswall")){
collision = tile.getTile().getProperties().get("collision", String.class);
}
}
if("true".equals(collision)){
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyDef.position.set(Detonator.WORLD_TO_BOX2D*((x*Terrain.tileWidth)-(Terrain.tileWidth / 2)), Detonator.WORLD_TO_BOX2D*(y*Terrain.tileHeight));
Body boxBody = map.world.createBody(bodyDef);
CircleShape circle = new CircleShape();
circle.setRadius(Detonator.WORLD_TO_BOX2D*8);
boxBody.createFixture(new CircleShape(),0.5f);
Log.info("COLLIDES, map coords: "+Detonator.WORLD_TO_BOX2D*((x*Terrain.tileWidth)-(Terrain.tileWidth / 2))+":"+Detonator.WORLD_TO_BOX2D*(y*Terrain.tileHeight));
}
}
}
}
}
}