Java 类com.badlogic.gdx.maps.Map 实例源码

项目:Entitas-Java    文件:Box2DMapObjectParser.java   
/**
 * @param map the {@link Map} which hierarchy to print
 * @return a human readable {@link String} containing the hierarchy of the {@link com.badlogic.gdx.maps.MapObjects} of the given {@link Map}
 */
public String getHierarchy(Map map) {
    String hierarchy = map.getClass().getName() + "\n", key, layerHierarchy;

    Iterator<String> keys = map.getProperties().getKeys();
    while (keys.hasNext())
        hierarchy += (key = keys.next()) + ": " + map.getProperties().get(key) + "\n";

    for (MapLayer layer : map.getLayers()) {
        hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getName() + "):\n";
        layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t");
        layerHierarchy = layerHierarchy.endsWith("\n\t\t") ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t")) : layerHierarchy;
        hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy;
    }

    return hierarchy;
}
项目:mario-game    文件:ParallaxLayer.java   
/**
 * Load the objects from the tmx file, convert them into textures and put them on the layer.
 */
private void loadObjects() {
    //TODO Use a spritesheet for the background objects
    Map map = world.getMap();
    Iterator<MapObject> it = map.getLayers().get(layer_name).getObjects().iterator();
    while(it.hasNext()) {
        MapObject obj = it.next();
        String file = "data/backgrounds/" + (String) obj.getProperties().get("src");
        layer_objects.add(obj);
        if(!layer_textures.containsKey(file)) {
            Texture texture = new Texture(file);
            texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
            layer_textures.put(file, texture);
        }
    }
}
项目:DreamsLibGdx    文件:Box2DMapObjectParser.java   
/**
 * @param map the {@link Map} which hierarchy to print
 * @return a human readable {@link String} containing the hierarchy of the {@link MapObjects} of the given {@link Map}
 */
public String getHierarchy(Map map) {
    String hierarchy = map.getClass().getName() + "\n", key, layerHierarchy;

    Iterator<String> keys = map.getProperties().getKeys();
    while (keys.hasNext())
        hierarchy += (key = keys.next()) + ": " + map.getProperties().get(key) + "\n";

    for (MapLayer layer : map.getLayers()) {
        hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getName() + "):\n";
        layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t");
        layerHierarchy = layerHierarchy.endsWith("\n\t\t") ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t")) : layerHierarchy;
        hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy;
    }

    return hierarchy;
}
项目:Entitas-Java    文件:Box2DMapObjectParser.java   
/**
 * creates the given {@link Map Map's} {@link com.badlogic.gdx.maps.MapObjects} in the given {@link World}
 *
 * @param world the {@link World} to create the {@link com.badlogic.gdx.maps.MapObjects} of the given {@link Map} in
 * @param map   the {@link Map} which {@link com.badlogic.gdx.maps.MapObjects} to create in the given {@link World}
 * @return the given {@link World} with the parsed {@link com.badlogic.gdx.maps.MapObjects} of the given {@link Map} created in it
 */
public World load(World world, Map map) {
    if (!ignoreMapUnitScale)
        unitScale = getProperty(map.getProperties(), aliases.unitScale, unitScale);
    box2dObjectFactory.setUnitScale(unitScale);
    tileWidth = getProperty(map.getProperties(), "tilewidth", (int) tileWidth);
    tileHeight = getProperty(map.getProperties(), "tileheight", (int) tileHeight);

    for (MapLayer mapLayer : map.getLayers())
        load(world, mapLayer);

    return world;
}
项目:ZombieCopter    文件:Level.java   
private void createDropOffPoints(Map map){
    logger.debug("Creating DropOffPoints");

    String layerName = "dropoff";

    //dropOffPoint map layer
    MapLayer layer = map.getLayers().get(layerName);
    if (layer == null) {
        logger.error("layer " + layerName + " does not exist");
        return;
    }

    //Layer objects
    MapObjects objects = layer.getObjects();
    for (MapObject mapObj : objects){

        //Object properties. 
        //name and position are set by the tiled editor. The rest are custom properties
        Vector2 position = new Vector2();
        float range = 1;

        MapProperties prop = mapObj.getProperties();
        Object x = prop.get("x"),
               y = prop.get("y"),
               r = prop.get("range");

        if (r != null) range = Float.parseFloat(r.toString());
        if (x != null && y != null)
            position.set((Float)x,(Float)y).scl(1/App.engine.PIXELS_PER_METER);                   
        App.engine.systems.dropoff.add(new DropOffPoint(position,range));   
    }       
}
项目:ZombieCopter    文件:Level.java   
private void createEntities(Map map) {

    logger.debug("Creating Entities");
    String layerName = "entities";

    MapLayer layer = map.getLayers().get(layerName);
    if (layer == null) {
        logger.error("layer " + layerName + " does not exist");
        return;
    }

    //Entity objects
    Vector2 position = new Vector2(),
    velocity = new Vector2();

    MapObjects objects = layer.getObjects();
    for (MapObject mapObj : objects){

        MapProperties prop = mapObj.getProperties();
        Object x = prop.get("x"),
               y = prop.get("y"),
               vx = prop.get("vx"),
               vy = prop.get("vy");

        position.set(0,0);
        velocity.set(0,0);

        if (x != null && y != null) 
            position.set((Float)x,(Float)y).scl(1/App.engine.PIXELS_PER_METER);
        if (vx != null && y != null)
            velocity.set((Float)vx,(Float)vy);
        logger.debug(" -Create: " + mapObj.getName());
        Entity e = App.engine.factory.build(mapObj.getName(),position,velocity);
        if (mapObj.getName().equals("player")) App.engine.systems.player.setPlayer(e);
    }
}
项目:mario-game    文件:WorldRenderer.java   
private void drawBackground(SpriteBatch batch, float posX, float posY) {
    batch.begin();
    Map map = world.getMap();
    int width = (Integer) map.getProperties().get("width");
    //getTexture("big_mountain").getWidth() * 
    batch.draw(background_image , -16 ,0 , width * 16, 16);
    batch.end();
}
项目:DreamsLibGdx    文件:Box2DMapObjectParser.java   
/**
 * creates the given {@link Map Map's} {@link MapObjects} in the given {@link World}
 *
 * @param world the {@link World} to create the {@link MapObjects} of the given {@link Map} in
 * @param map   the {@link Map} which {@link MapObjects} to create in the given {@link World}
 * @return the given {@link World} with the parsed {@link MapObjects} of the given {@link Map} created in it
 */
public World load(World world, Map map) {
    if (!ignoreMapUnitScale)
        unitScale = getProperty(map.getProperties(), aliases.unitScale, unitScale);
    box2dObjectFactory.setUnitScale(unitScale);
    tileWidth = getProperty(map.getProperties(), "tilewidth", (int) tileWidth);
    tileHeight = getProperty(map.getProperties(), "tileheight", (int) tileHeight);

    for (MapLayer mapLayer : map.getLayers())
        load(world, mapLayer);

    return world;
}
项目:ZombieCopter    文件:Level.java   
private void createSpawnZones(Map map){
    logger.debug("Creating SpawnPoints");

    String layerName = "spawn";

    //spawnPoint map layer
    MapLayer layer = map.getLayers().get(layerName);
    if (layer == null) {
        logger.error("layer " + layerName + " does not exist");
        return;
    }

    //Layer objects
    float units = App.engine.PIXELS_PER_METER;
    MapObjects objects = layer.getObjects();
    for (MapObject mapObj : objects){
        logger.debug("found spawn zone");
        //Spawn area rectangle
        Rectangle rect;

        if (mapObj instanceof RectangleMapObject){
            rect = ((RectangleMapObject) mapObj).getRectangle();
            rect.height /= units;
            rect.width /= units;
            rect.x /= units;
            rect.y /= units;            
        }
        else {
            logger.error("spawn zones should only be rectangles");
            continue;
        }

        //Object properties. 
        //name and position are set by the tiled editor. The rest are custom properties
        String  name = mapObj.getName();
        int     maximum = 0;
        float   delay = 3;

        logger.debug("Creating '" + name + "' spawn zone");

        MapProperties prop = mapObj.getProperties();
        Object max = prop.get("maximum"),
               dly = prop.get("delay");

        if (max != null) maximum = Integer.parseInt(max.toString());
        if (dly != null) delay = Float.parseFloat(dly.toString());
        SpawnSystem spawner = App.engine.systems.spawn;
        spawner.add(new SpawnZone(rect,name,maximum,delay));    
    }       
}
项目:sioncore    文件:MapBodyManager.java   
/**
 * @param map will use the "physics" layer of this map to look for shapes in order to create the static bodies.
 */
public void createPhysics(Map map) {
    createPhysics(map, "physics");
}
项目:sioncore    文件:MapBodyManager.java   
/**
 * @param map map to be used to create the static bodies. 
 * @param layerName name of the layer that contains the shapes.
 */
public void createPhysics(Map map, String layerName) {
    MapLayer layer = map.getLayers().get(layerName);

    if (layer == null) {
        logger.error("layer " + layerName + " does not exist");
        return;
    }

    MapObjects objects = layer.getObjects();
    Iterator<MapObject> objectIt = objects.iterator();

    while(objectIt.hasNext()) {
        MapObject object = objectIt.next();

        if (object instanceof TextureMapObject){
            continue;
        }

        Shape shape;
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.StaticBody;

        if (object instanceof RectangleMapObject) {
            RectangleMapObject rectangle = (RectangleMapObject)object;
            shape = getRectangle(rectangle);
        }
        else if (object instanceof PolygonMapObject) {
            shape = getPolygon((PolygonMapObject)object);
        }
        else if (object instanceof PolylineMapObject) {
            shape = getPolyline((PolylineMapObject)object);
        }
        else if (object instanceof CircleMapObject) {
            shape = getCircle((CircleMapObject)object);
        }
        else {
            logger.error("non suported shape " + object);
            continue;
        }

        MapProperties properties = object.getProperties();
        String material = properties.get("material", "default", String.class);
        FixtureDef fixtureDef = materials.get(material);

        if (fixtureDef == null) {
            logger.error("material does not exist " + material + " using default");
            fixtureDef = materials.get("default");
        }

        fixtureDef.shape = shape;
        fixtureDef.filter.categoryBits = Env.game.getCategoryBitsManager().getCategoryBits("level");

        Body body = world.createBody(bodyDef);
        body.createFixture(fixtureDef);

        bodies.add(body);

        fixtureDef.shape = null;
        shape.dispose();
    }
}
项目:ninja-rabbit    文件:LevelPhysicsProcessor.java   
public LevelPhysicsProcessor(final World world, final Map map, final float unitScale) {
    b2dRenderer = new Box2DDebugRenderer();
    mapObjectListener = new Box2DMapObjectListener();
    Box2DMapObjectParser objectParser = new Box2DMapObjectParser(mapObjectListener, unitScale);
    objectParser.load(world, map);
}
项目:Interplanar    文件:Level.java   
public Level(Map map) {
    this.map = map;

    MapLayer collisionLayer = map.getLayers().get("Collision");
    collisionObjects = collisionLayer.getObjects();
}
项目:Interplanar    文件:Level.java   
public static Level fromMapPath(String filePath) {
    Map map = new TmxMapLoader().load(filePath);

    return new Level(map);
}
项目:feup-lpoo-armadillo    文件:B2DWorldCreator.java   
/**
 * B2DWorldCreator's constructor.
 * In loads the given map to the given world.
 *
 * @param world World to were the map elements will be loaded.
 * @param map   Map to load the world elements from.
 */
public B2DWorldCreator(World world, Map map) {
    this.world = world;
    this.map = map;

    addLayerLoaders();
}
项目:JavaLib    文件:MapBodyManager.java   
/**
 * @param map
 *            will use the "physics" layer of this map to look for shapes in
 *            order to create the static bodies.
 */
public void createPhysics(Map map) {
    createPhysics(map, "physics");
}