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

项目:KyperBox    文件:GameState.java   
private void loadFonts(TiledMap data, String atlasname) {
    MapObjects objects = data.getLayers().get("preload").getObjects();
    String ffcheck = "Font";
    for (MapObject o : objects) {
        String name = o.getName();
        BitmapFont font = null;
        MapProperties properties = o.getProperties();
        String type = properties.get("type", String.class);
        String fontfile = properties.get("font_file", String.class);
        if (fontfile != null && type != null && type.equals(ffcheck)) {
            boolean markup = properties.get("markup", false, boolean.class);
            game.loadFont(fontfile, atlasname);
            game.getAssetManager().finishLoading();
            font = game.getFont(fontfile);
            fonts.put(name, font);
            font.getData().markupEnabled = markup;
        }
    }
}
项目:KyperBox    文件:GameState.java   
private void loadParticleEffects(TiledMap data, String atlasname) {
    MapObjects objects = data.getLayers().get("preload").getObjects();
    String ppcheck = "Particle";
    for (MapObject o : objects) {
        String name = o.getName();
        MapProperties properties = o.getProperties();
        String type = properties.get("type", String.class);
        if (type != null && type.equals(ppcheck)) {
            String file = properties.get("particle_file", String.class);
            if (file != null) {
                game.loadParticleEffect(file, atlasname);
                game.getAssetManager().finishLoading();
                if (!particle_effects.containsKey(name)) {
                    ParticleEffect pe = game.getParticleEffect(file);
                    pe.setEmittersCleanUpBlendFunction(false);
                    pvalues.add(KyperBoxGame.PARTICLE_FOLDER + KyperBoxGame.FILE_SEPARATOR + file);
                    particle_effects.put(name, new ParticleEffectPool(pe, 12, 48));
                }
            }
        }
    }
}
项目:KyperBox    文件:GameState.java   
private void loadShaders(TiledMap data) {
    MapObjects objects = data.getLayers().get("preload").getObjects();
    String scheck = "Shader";
    for (MapObject o : objects) {
        String name = o.getName();
        MapProperties properties = o.getProperties();
        String type = properties.get("type", String.class);
        if (type != null && type.equals(scheck)) {
            String file = properties.get("shader_name", String.class);
            if (file != null) {
                game.loadShader(file);
                game.getAssetManager().finishLoading();
                if (!shaders.containsKey(name)) {
                    ShaderProgram sp = game.getShader(file);
                    shaders.put(name, sp);
                    svalues.add(KyperBoxGame.SHADER_FOLDER + KyperBoxGame.FILE_SEPARATOR + file);
                }
            }
        }
    }
}
项目:fabulae    文件:GameMapLoader.java   
private void loadCharacterGroups() throws IOException {
    MapLayer groupsLayer = map.getLayers().get(LAYER_GROUPS);
    if (groupsLayer == null) {
        return;
    }
    MapObjects groups = groupsLayer.getObjects();
    for (MapObject mapGroup : groups) {
        if (mapGroup.getName() == null) {
            continue;
        }
        String groupFile = mapGroup.getName();
        String id = (String) mapGroup.getProperties().get(PROPERTY_ID);
        if (id == null) {
            id = groupFile;
        }

        Vector2 position = getPositionFromMapObject(mapGroup);
        CharacterGroupGameObject group = new CharacterGroupGameObject(id, Gdx.files.internal(Configuration
                .getFolderGroups() + groupFile + ".xml"), gameMap);
        group.position().set((int) (position.x / gameMap.getTileSizeX()),
                (int) (position.y / gameMap.getTileSizeY()));
    }
}
项目:fabulae    文件:GameMapLoader.java   
private void loadItems() throws IOException {
    MapLayer itemsLayer = map.getLayers().get(LAYER_ITEMS);
    if (itemsLayer == null) {
        return;
    }
    MapObjects items = itemsLayer.getObjects();
    for (MapObject item : items) {
        Vector2 position = getPositionFromMapObject(item);
        PickableGameObject newItem = new PickableGameObject(item.getName());
        newItem.getOwner().set(item.getProperties().get(PROPERTY_OWNER_CHARACTER, String.class),
                Faction.getFaction(item.getProperties().get(PROPERTY_OWNER_FACTION, String.class)),
                Boolean.valueOf(item.getProperties().get(PROPERTY_OWNER_FIXED, "false", String.class)));
        newItem.position().set(position.x / gameMap.getTileSizeX(), position.y / gameMap.getTileSizeY());
        newItem.setMap(gameMap);
        newItem.setOffsets(newItem.getXOffset() + getInteger(item, PROPERTY_XOFFSET, 0) * gameMap.getScaleX(),
                newItem.getYOffset() + getInteger(item, PROPERTY_YOFFSET, 0) * gameMap.getScaleY());
    }
}
项目:fabulae    文件:GameMapLoader.java   
private void loadLocations(MapLayer locationsLayer, boolean loadTraps) throws IOException {
    if (locationsLayer == null) {
        return;
    }
    MapObjects locations = locationsLayer.getObjects();
    for (MapObject location : locations) {
        String locId = location.getProperties().get(PROPERTY_ID, location.getName(), String.class)
                .toLowerCase(Locale.ENGLISH);
        String locType = location.getName();
        SaveablePolygon locPolygon = transformTiledPolygon(gameMap, getPolygonFromMapObject(location));
        GameLocation newLocation = loadTraps ? new TrapLocation(locId, locType, locPolygon,
                Boolean.valueOf(location.getProperties().get(PROPERTY_DETECTED, "false", String.class)),
                Boolean.valueOf(location.getProperties().get(PROPERTY_DISARMED, "false", String.class)))
                : new GameLocation(locId, locType, locPolygon);
        newLocation.setMap(gameMap);
        newLocation.loadFromXML(Gdx.files.internal(Configuration.getFolderLocations() + locType + ".xml"));
    }

    for (GameObject go : gameMap.gameObjects) {
        if (go instanceof GameCharacter) {
            ((GameCharacter) go).calculateCurrentLocations();
        }
    }
}
项目:fabulae    文件:GameMapLoader.java   
private void loadTransitions() {
    MapLayer locationsLayer = map.getLayers().get(LAYER_TRANSITIONS);
    if (locationsLayer == null) {
        return;
    }
    Array<Transition> transitions = new Array<Transition>();
    MapObjects locations = locationsLayer.getObjects();
    for (MapObject location : locations) {
        MapObject mapObject = (MapObject) location;
        String[] coords = ((String) mapObject.getProperties().get(PROPERTY_TARGET)).split(",");
        Tile target = new Tile(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()));

        Polygon polygon = getPolygonFromMapObject(mapObject);
        Transition newTransition = new Transition(gameMap, mapObject.getName(), target.getX(), target.getY(),
                transformTiledPolygon(gameMap, polygon));
        transitions.add(newTransition);
    }
    buildTransitionTiles(transitions);
}
项目:Mario-Libgdx    文件:TmxMap.java   
private void initMapObjects() {

    items = new ArrayList<AbstractItem>();
    enemies = new ArrayList<AbstractEnemy>();
    sfxSprites = new ArrayList<AbstractSfxSprite>();
    plateforms = new ArrayList<AbstractMetalPlateform>();

    MapObjects objects = objectsLayer.getObjects();
    for (MapObject mapObject : objects) {

        MapProperties objectProperty = mapObject.getProperties();                                   
        if (objectProperty.get("type").toString().equals("mario")) {
            mario = new Mario(mapObject);
        }
        initEnemies(mapObject, objectProperty);
        initItems(mapObject, objectProperty);
        initSfxSprites(mapObject, objectProperty);
    }
}
项目:AI_TestBed_v3    文件:Level.java   
public void loadLevelObjects() {
    MapLayer mapLayerMission = getMap().getLayers().get(LAYER_MISSIONOBJECTS);

    MapObjects objects = mapLayerMission.getObjects();

    for (int i = 0; i < objects.getCount(); i++) {
        MapObject mapObj = objects.get(i);

        SpawnableBase base = EntityFactory.getEntity(mapObj.getName());
        if (base != null) {
            base.prepareFromMap(getLevelID(), mapObj);
        }
    }

    Logger.dbg("map objects loaded!");
}
项目:mario-game    文件:World.java   
private Array<Goomba> generateEnemies() {
    Array<Goomba> goombas = new Array<Goomba>();
    MapLayer layer = map.getLayers().get("objects");
    MapObjects objects = layer.getObjects();
    Iterator<MapObject> objectIt = objects.iterator();
    while(objectIt.hasNext()) {
        MapObject obj = objectIt.next();
        String type = (String) obj.getProperties().get("type");
        if(type != null) {
            float x = (Float) obj.getProperties().get("x");
            float y = (Float) obj.getProperties().get("y");
            if(type.equals("goomba")) {
                Goomba goomba = new Goomba(this, x * (1/16f), y* (1/16f));
                goombas.add(goomba);
                stage.addActor(goomba);
            }
        }
    }
    return goombas;
}
项目:mario-game    文件:World.java   
/**
 * Check if there are items in a brick, if there are they are added to the brick.
 * @param brick
 * @param x
 * @param y
 */
private void itemsInBrick(Brick brick, int x, int y) {
    MapLayer layer = map.getLayers().get("hidden_items");
    MapObjects objects = layer.getObjects();
    for(MapObject obj : objects) {

        int obj_x = (int) ((Float) obj.getProperties().get("x") * (1/16f));
        int obj_y = (int) ((Float) obj.getProperties().get("y") * (1/16f));
        if(obj_x == x && obj_y == y) {
            String type = (String) obj.getProperties().get("type");
            Actor item = null;
            if(type.equals("super_mushroom")) {
                item = new Super(this, x, y, 4f);
                mushrooms.add((Mushroom) item);
            }
            stage.addActor(item);               
            brick.addItem(item);
        }
    }
}
项目:Elementorum    文件:Level.java   
public Level() {
    super("Game");

    cam = new OrthographicCamera();
    // Setup camera viewport
    cam.setToOrtho(false, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    cam.update();

    batch = new SpriteBatch();
    // Load map
    map =  new TmxMapLoader().load("maps/Lvl1.tmx");
    mapRenderer = new OrthogonalTiledMapRenderer(map);

    // Load walls as rectangles in an array
    MapObjects wallobjects = map.getLayers().get("Walls").getObjects();
    for(int i = 0; i < wallobjects.getCount(); i++) {
        RectangleMapObject obj = (RectangleMapObject) wallobjects.get(i);
        Rectangle rect = obj.getRectangle();
        walls.add(new Rectangle(rect.x, rect.y, 16, 16));
    }
    Texture[] tex = new Texture[]{new Texture("sprites/Player_Side_Left.png"),new  Texture("sprites/Player_Side_Right.png"), new Texture("sprites/Player_Behind_1.png"), new Texture("sprites/Player_Behind_2.png"),new Texture("sprites/Player_Forward1.png"),new Texture("sprites/Player.png")};
    player = new Player("sprites/Player.png", 120, 120, walls, tex);
    wall = new Texture("tiles/Wall.png");
}
项目:Secludedness    文件:Level.java   
private void setPlayerStartInformation(MapObjects mapObjects) {
    if (mapObjects == null || mapObjects.getCount() != 1) {
        throw new GdxRuntimeException("Invalid map: Only one player start position allowed!");
    }

    Rectangle playerBox = ((RectangleMapObject) mapObjects.get("startpoint")).getRectangle();       
    mPlayerCell = new int[2];
    mPlayerCell[0] = (int) Math.floor(playerBox.getX());
    mPlayerCell[1] = (int) Math.floor(playerBox.getY());

    String healthProperty = (String) mapObjects.get("startpoint").getProperties().get("health");
    if (healthProperty != null) {
        mPlayerStartHealth = Integer.parseInt(healthProperty);
    } else {
        mPlayerStartHealth = 10;
    }

    // Remove fog on start position
    if (mFogLayer != null) {
        removeFog(mPlayerCell[0], mPlayerCell[1]);
    }
}
项目:Cypher-Sydekick    文件:RandomLevel.java   
/**
 * Create an npc object on the map
 * 
 * @param pillarNum
 *            - the pillar this npc controls
 * @param tileX
 *            - npc x pos in tiles
 * @param tileY
 *            - npc y pos in tiles
 * @param objs
 *            - the maps objects
 * @param loader
 *            - body loader to load body
 * @param world
 *            - physics world
 */
private void makeNPC(String name, boolean hasKey, int pillarNum,
        float tileX, float tileY, MapObjects objs, BodyEditorLoader loader,
        World world) {

    MapObject npc = new MapObject();

    npc.getProperties().put("x", (int) (tileX * TILE_WIDTH));
    npc.getProperties().put("y", (int) (tileY * TILE_HEIGHT));
    npc.getProperties().put("gid", NPC_ID);
    npc.getProperties().put("type", "npc");
    npc.getProperties().put("used", false);
    npc.getProperties().put("pillarNum", pillarNum);
    npc.getProperties().put("hasKey", hasKey);
    npc.setName(name);
    BodyFactory
            .createBody(world, "tile", BodyType.StaticBody, tileX, tileY);

    objs.add(npc);

}
项目:Cypher-Sydekick    文件:RandomLevel.java   
/**
 * Create a pillar object on the map
 * 
 * @param pillarNum
 *            - the number of this pillar
 * @param tileX
 *            - pillar x pos in tiles
 * @param tileY
 *            - pillar y pos in tiles
 * @param objs
 *            - the maps objects
 * @param loader
 *            - body loader to load body
 * @param world
 *            - physics world
 */
private void makePillar(int pillarNum, float tileX, float tileY,
        MapObjects objs, BodyEditorLoader loader, World world) {
    MapObject pillarTop = new MapObject();
    MapObject pillarBottom = new MapObject();

    pillarTop.getProperties().put("x", (int) (tileX * TILE_WIDTH));
    pillarTop.getProperties().put("y", (int) ((tileY + 1) * TILE_HEIGHT));
    pillarTop.getProperties().put("pillarNum", pillarNum);
    pillarTop.getProperties().put("gid", PILLAR_OFF_TOP_ID);

    pillarBottom.getProperties().put("x", (int) (tileX * TILE_WIDTH));
    pillarBottom.getProperties().put("y", (int) (tileY * TILE_HEIGHT));
    pillarBottom.getProperties().put("gid", PILLAR_OFF_BOTTOM_ID);
    pillarBottom.getProperties().put("pillarNum", pillarNum);
    BodyFactory.createBody(world, "pillar", BodyType.StaticBody, tileX,
            tileY);

    objs.add(pillarBottom);
    objs.add(pillarTop);
}
项目:KyperBox    文件:GameState.java   
private void loadUi(MapLayer layer, TextureAtlas atlas) {
    MapObjects objects = layer.getObjects();
    Array<String> added = new Array<String>();
    for (MapObject o : objects) {
        MapProperties properties = o.getProperties();
        Actor ui_actor = getUiActor(added, o, properties, objects, atlas);
        if (ui_actor != null)
            uiground.addActor(ui_actor);

    }
}
项目:GangsterSquirrel    文件:InteractiveMapTileObject.java   
/**
 * This method returns the properties of an object in a collision layer by checking the player rectangle and object rectangle for an intersection
 * @param layerIndex the index of the layer in which to search for objects
 * @return the collided object
 */
protected MapObject getCollidingMapObject(int layerIndex) {
    MapObjects mapObjects = map.getLayers().get(layerIndex).getObjects();

    for (MapObject mapObject : mapObjects) {
        MapProperties mapProperties = mapObject.getProperties();

        float width, height, x, y;
        Rectangle objectRectangle = new Rectangle();
        Rectangle playerRectangle = new Rectangle();

        if (mapProperties.containsKey("width") && mapProperties.containsKey("height") && mapProperties.containsKey("x") && mapProperties.containsKey("y")) {
            width = (float) mapProperties.get("width");
            height = (float) mapProperties.get("height");
            x = (float) mapProperties.get("x");
            y = (float) mapProperties.get("y");
            objectRectangle.set(x, y, width, height);
        }

        playerRectangle.set(
                playScreen.getPlayer().getX() * MainGameClass.PPM,
                playScreen.getPlayer().getY() * MainGameClass.PPM,
                playScreen.getPlayer().getWidth() * MainGameClass.PPM,
                playScreen.getPlayer().getHeight() * MainGameClass.PPM
        );

        // If the player rectangle and the object rectangle is colliding, return the object
        if (Intersector.overlaps(objectRectangle, playerRectangle)) {
            return mapObject;
        }
    }

    // If no colliding object was found in that layer
    return null;
}
项目:fabulae    文件:GameMapLoader.java   
private void loadUsables() throws IOException {
    MapLayer itemsLayer = map.getLayers().get(LAYER_USABLES);
    if (itemsLayer == null) {
        return;
    }
    MapObjects items = itemsLayer.getObjects();
    for (MapObject item : items) {
        Polygon polygon = getPolygonFromMapObject(item);
        if (item.getName() == null) {
            continue;
        }
        String type = item.getName();
        Object idValue = item.getProperties().get(PROPERTY_ID);
        String id = idValue instanceof String ? (String) idValue : null;
        if (id == null) {
            id = type;
        }

        UsableGameObject newItem = new UsableGameObject(id, Gdx.files.internal(Configuration.getFolderUsables()
                + type + ".xml"), transformTiledPolygon(gameMap, polygon), gameMap);

        String orientationProp = item.getProperties().get(PROPERTY_ORIENTATION, null, String.class);
        if (orientationProp != null) {
            newItem.setOrientation(Orientation.valueOf(orientationProp.toUpperCase(Locale.ENGLISH)));
        }

        String groundProp = item.getProperties().get(PROPERTY_GROUND, null, String.class);
        if (groundProp != null) {
            String[] coords = groundProp.split(",");
            newItem.setGround(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()));
        }
        newItem.setOffsets(newItem.getXOffset() + getInteger(item, PROPERTY_XOFFSET, 0) * gameMap.getScaleX(),
                newItem.getYOffset() + getInteger(item, PROPERTY_YOFFSET, 0) * gameMap.getScaleY());
    }
}
项目:braingdx    文件:StatePopulator.java   
private void handleObjectLayer(int layerIndex, MapLayer layer, State state, TiledMapConfig config) {
   MapObjects mapObjects = layer.getObjects();
   for (int objectIndex = 0; objectIndex < mapObjects.getCount(); ++objectIndex) {
      MapObject mapObject = mapObjects.get(objectIndex);
      MapProperties objectProperties = mapObject.getProperties();
      GameObject gameObject = gameWorld.addObject();
      final float x = objectProperties.get(config.get(Constants.X), Float.class);
      final float y = objectProperties.get(config.get(Constants.Y), Float.class);
      final float w = objectProperties.get(config.get(Constants.WIDTH), Float.class);
      final float h = objectProperties.get(config.get(Constants.HEIGHT), Float.class);
      final float cellWidth = state.getCellWidth();
      final float cellHeight = state.getCellHeight();
      Object objectType = objectProperties.get(config.get(Constants.TYPE));
      boolean collision = objectProperties.get(config.get(Constants.COLLISION), true, Boolean.class);
      gameObject.setPosition(x, y);
      gameObject.setDimensions(IndexCalculator.calculateIndexedDimension(w, cellWidth),
            IndexCalculator.calculateIndexedDimension(h, cellHeight));
      gameObject.setLastPosition(x, y);
      gameObject.setColor(mapObject.getColor());
      gameObject.setType(objectType);
      gameObject.setAttribute(Constants.LAYER_INDEX, layerIndex);
      gameObject.setAttribute(MapProperties.class, objectProperties);
      if (objectProperties.containsKey(config.get(Constants.MOVEMENT))) {
         String className = objectProperties.get(config.get(Constants.MOVEMENT), String.class);
         RasteredMovementBehavior behavior = createMovementBehavior(className);
         if (behavior != null) {
            behaviorManager.apply(behavior, gameObject);
         }
      }
      CollisionCalculator.updateCollision(collision, x, y, layerIndex, state);
      IndexCalculator.calculateZIndex(gameObject, state, layerIndex);
      for (TiledMapListener listener : listeners) {
         listener.onLoadGameObject(gameObject, api);
      }
   }
}
项目: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);
    }
}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param map
 */
public void createBodies(ArrayList<Entity> entities, World world, TiledMap map){
    MapObjects objects;

    objects = map.getLayers().get("ground").getObjects();
    for(MapObject object : objects){
        if(object instanceof RectangleMapObject){
            createRectangle(world, (RectangleMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolygonMapObject){
            createPolygon(world, (PolygonMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolylineMapObject){
            createPolyline(world, (PolylineMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof EllipseMapObject){
            createEllipse(world, (EllipseMapObject) object, 0.5f, 0.4f, 0.6f);
        } else{
            Gdx.app.error("Error", "Invalid map object");
        }
    }

    /*
    objects = map.getLayers().get("dynamic").getObjects();
    for(MapObject object : objects){
        RectangleMapObject entity = (RectangleMapObject) object;
        Rectangle position = entity.getRectangle();
        entities.add(new Box(world, new Vector2(position.x / SupaBox.PPM, position.y / SupaBox.PPM), new Vector2(0f, 0f), 1f, 1f));
    }
    */
}
项目:MMORPG_Prototype    文件:PlayState.java   
private void insertMapObjectsIntoCollisionMap(PixelCollisionMap<GameObject> collisionMap, TiledMap worldMap)
{
    MapObjects objects = worldMap.getLayers().get("CollisionLayer").getObjects();
    Array<RectangleMapObject> collision = objects.getByType(RectangleMapObject.class);
    collision.forEach((rectangle) -> collisionMap.insertStaticObject(rectangle.getRectangle()));
}
项目:MMORPG_Prototype    文件:PlayState.java   
private void loadCollision(TiledMap map)
{
    MapObjects objects = map.getLayers().get("CollisionLayer").getObjects();
    Array<RectangleMapObject> collision = objects.getByType(RectangleMapObject.class);
    collision.forEach((rectangle) -> collisionMap.insert(new MapCollisionUnknownObject(rectangle.getRectangle())));
}
项目:MMORPG_Prototype    文件:PlayState.java   
private void loadSpawners(TiledMap map)
{
    MapObjects objects = map.getLayers().get("SpawnAreasLayer").getObjects();
    Array<RectangleMapObject> spawnerInfos = objects.getByType(RectangleMapObject.class);
    spawnerInfos.forEach(spawnerElement -> addSpawner(spawnerElement));
}
项目:EvilBunnyGod    文件:World.java   
private void loadLevel(String level) {
    // load tile map
    TmxMapLoader.Parameters params = new TmxMapLoader.Parameters();
    params.textureMinFilter = TextureFilter.Linear;
    params.textureMagFilter = TextureFilter.Linear;
    map = new TmxMapLoader().load(level);
    mapWidth = map.getProperties().get("width", Integer.class);
    tileWidth = map.getProperties().get("tilewidth", Integer.class);
    mapHeight = map.getProperties().get("height", Integer.class);
    tileHeight = map.getProperties().get("tileheight", Integer.class);
    // load objects from map
    MapObjects objects = map.getLayers().get("objects").getObjects();
    // create objects
    for (int i = 0; i < objects.getCount(); i++) {
        MapProperties object = objects.get(i).getProperties();
        String type = object.get("type", String.class);
        if (type.equals("bunny")) {

            Bunny bunny = new Bunny(object.get("x", Float.class), object.get("y", Float.class));
            bunny.position.scl(1f / TILE_SIZE);
            bunny.bounds.y /= TILE_SIZE;
            bunny.bounds.x /= TILE_SIZE;
            entities.add(bunny);
            bunnies.add(bunny);
        } else if (type.equals("house")) {
            House house = new House(object.get("x", Float.class), object.get("y", Float.class));
            house.position.scl(1f / TILE_SIZE);
            entities.add(house);
            houses.add(house);
        } else if (type.equals("fence")) {
            Fence fence = new Fence(object.get("x", Float.class), object.get("y", Float.class));
            fence.position.scl(1f / TILE_SIZE);
            entities.add(fence);
        } else if (type.equals("trap")) {
            Trap trap = new Trap(object.get("x", Float.class), object.get("y", Float.class));
            trap.position.scl(1f / TILE_SIZE);
            entities.add(trap);
        } else if (type.equals("cornfield")) {
            Cornfield cf = new Cornfield(object.get("x", Float.class), object.get("y", Float.class));
            cf.position.scl(1f / TILE_SIZE);
            entities.add(cf);
        }
    }
}
项目:joe    文件:MapLayerWrapper.java   
public MapObjects getObjects() {
    return rawLayer.getObjects();
}
项目:fabulae    文件:GameMapLoader.java   
private void loadCharacters() throws IOException {
    MapLayer npcLayer = map.getLayers().get(LAYER_NPCS);
    if (npcLayer == null) {
        return;
    }
    MapObjects npcs = npcLayer.getObjects();
    for (MapObject mapNpc : npcs) {
        if (mapNpc.getName() == null) {
            continue;
        }
        String type = mapNpc.getName();
        String role = (String) mapNpc.getProperties().get(PROPERTY_ROLE);
        String id = (String) mapNpc.getProperties().get(PROPERTY_ID);
        if (id == null) {
            id = type;
        }

        GameCharacter character = null;

        character = GameCharacter.loadCharacter(id,
                Gdx.files.internal(Configuration.getFolderCharacters() + type + ".xml"), gameMap);

        if (role != null) {
            GameCharacter playerCreatedCharacter = GameState.getPlayerCharacterGroup().getCreatedCharacter(
                    Role.getRole(role));
            if (playerCreatedCharacter != null) {
                playerCreatedCharacter.setId(character.getId());
                playerCreatedCharacter.brain().setAIScript(character.brain().getAIScript());
                playerCreatedCharacter.setDialogueId(character.getDialogueId());
                int level = character.stats().getLevel();
                while (playerCreatedCharacter.stats().getLevel() < level) {
                    playerCreatedCharacter.stats().levelUp();
                }
                playerCreatedCharacter.getInventory().clear();
                playerCreatedCharacter.setOrientation(character.getOrientation());
                character.getInventory().copyAllItemsTo(playerCreatedCharacter.getInventory());
                playerCreatedCharacter.stats().setExperienceValue(character.stats().getExperienceValue());
                playerCreatedCharacter.stats().setExperience(
                        Configuration.getExperienceTable().getRequiredExperienceTotalForLevel(level));

                character.remove();
                character = playerCreatedCharacter;
                character.undispose();
                character.setMap(gameMap);
            }
        }

        Vector2 position = getPositionFromMapObject(mapNpc);
        character.position().set((int) (position.x / gameMap.getTileSizeX()),
                (int) (position.y / gameMap.getTileSizeY()));
    }
}
项目: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));    
    }       
}
项目:practicos    文件:GeneradorNivel.java   
private void crearColisiones() {

Array<Body> slopes = new Array<Body>();
FixtureDef fixDef = new FixtureDef();


MapObjects objects = cls.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 EllipseMapObject) {
    shape = getEllipse((EllipseMapObject)object);
}
else if (object instanceof CircleMapObject) {
    shape = getCircle((CircleMapObject)object);
}
else {
    continue;
}


fixDef.shape = shape;
fixDef.filter.categoryBits = GameWorld.BIT_PARED;
  fixDef.filter.maskBits = GameWorld.BIT_JUGADOR | GameWorld.BIT_ENEMIGOS | GameWorld.BIT_SENSOR;


Body suelo = GameWorld.mundo.createBody(bodyDef);
suelo.createFixture(fixDef).setUserData("cls");

slopes.add(suelo);

shape.dispose();
  }
}
项目: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();
    }
}
项目:rts-engine    文件:RTSAbstractMap.java   
@Override
   public MapObjects getMapObjects() {
return mapObjects;
   }
项目:GdxStudio    文件:Map.java   
public MapObjects getMapObjects(){
    return mobjects;
}
项目:cocos2d-java    文件:TMXTiledMap.java   
/** Return the TMXObjectGroup for the specific group. 
 * 
 * @return Return the TMXObjectGroup for the specific group.
 */
public MapObjects getObjectGroup(String groupName) {
 return _tileMap.getLayers().get(groupName).getObjects();
}
项目:rts-engine    文件:IRTSMap.java   
public MapObjects getMapObjects();