Java源码示例:com.badlogic.gdx.maps.MapObject

示例1
private void createModelObject(World world, MapObject object) {
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.hero))
        box2dObjectFactory.createEntity(GRUPO.HERO, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.movingPlatform))
        box2dObjectFactory.createEntity(GRUPO.MOVING_PLATFORM, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.water))
        box2dObjectFactory.createEntity(GRUPO.FLUID, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.enemy))
        box2dObjectFactory.createEntity(GRUPO.ENEMY, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.item))
        box2dObjectFactory.createEntity(GRUPO.ITEMS, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.millObject))
        box2dObjectFactory.createEntity(GRUPO.MILL, object);
    if (object.getProperties().get(aliases.typeModelObject).equals(aliases.checkPointObject))
        box2dObjectFactory.createEntity(GRUPO.CHECKPOINT, object);

}
 
示例2
private void createMeshes () {
	staticMeshes.clear();
	TotalMeshes = 0;

	// static meshes layer
	if (mapUtils.hasObjectGroup(ObjectGroup.StaticMeshes)) {
		MapLayer group = mapUtils.getObjectGroup(ObjectGroup.StaticMeshes);
		for (int i = 0; i < group.getObjects().getCount(); i++) {
			MapObject o = group.getObjects().get(i);

			float scale = 1f;
			if (o.getProperties().get(ObjectProperties.MeshScale.mnemonic) != null) {
				scale = Float.parseFloat(o.getProperties().get(ObjectProperties.MeshScale.mnemonic, String.class));
			}

			// @off
			OrthographicAlignedStillModel mesh = ModelFactory.create(
				o.getProperties().get("type", String.class),
				o.getProperties().get("x", Integer.class),
				o.getProperties().get("y", Integer.class),
				scale * pixelsPerMeterFactor
			);
			// @on

			if (mesh != null) {
				staticMeshes.add(mesh);
			}
		}
	}

	// walls by polylines
	List<OrthographicAlignedStillModel> walls = createWalls();
	trackWalls = new TrackWalls(walls);

	// trees
	List<TreeStillModel> trees = createTrees();
	trackTrees = new TrackTrees(trees);

	TotalMeshes = staticMeshes.size() + trackWalls.count() + trackTrees.count();
}
 
示例3
private void fillSpawnPositions() {
	for (final MapObject object : spawnsLayer.getObjects()) {
		if (object.getName().equalsIgnoreCase(PLAYER_START)) {
			addPositions(object, unitSpawnPositions, true);
		}

		if (object.getName().equalsIgnoreCase(ENEMY_START)) {
			addPositions(object, enemyStartPositions, false);
		}
	}
}
 
示例4
private void addPositions(MapObject object, ArrayList<TiledMapPosition> startPositions, boolean isHuman) {
	((RectangleMapObject) object).getRectangle().getPosition(playerStartPositionRect);
	final TiledMapPosition spawnPos = new TiledMapPosition().setPositionFromTiled(playerStartPositionRect.x, playerStartPositionRect.y);
	startPositions.add(spawnPos);

	final TiledMapActor tiledactor = getActorAtScreenCoordinate(spawnPos);

	setSpawns(isHuman, tiledactor);
}
 
示例5
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}
 
示例6
/**
 * @param layer the {@link MapLayer} 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 MapLayer}
 */
public String getHierarchy(MapLayer layer) {
    String hierarchy = "", key;

    for (MapObject object : layer.getObjects()) {
        hierarchy += object.getName() + " (" + object.getClass().getName() + "):\n";
        Iterator<String> keys = object.getProperties().getKeys();
        while (keys.hasNext())
            hierarchy += "\t" + (key = keys.next()) + ": " + object.getProperties().get(key) + "\n";
    }

    return hierarchy;
}
 
示例7
public void loadLevel(String level, boolean isServer, String name) {
    this.isServer = isServer;
    map = new TmxMapLoader().load(level);
    TiledMapTileLayer layer = (TiledMapTileLayer) map.
                                getLayers().get("terrain");
    VIEWPORT_WIDTH = (int) (layer.getTileWidth() * layer.getWidth());
    VIEWPORT_HEIGHT = (int) (layer.getTileHeight() * layer.getHeight());
    viewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, camera);
    renderer = new OrthogonalTiledMapRenderer(map);
    name = name.trim();
    if (name.length() == 0)
        name = "noname";
    if (name.length() >= 10){
        name = name.substring(0, 10);
    }
    ClientDetailsMessage clientDetails = new ClientDetailsMessage();
    clientDetails.name = name;
    clientDetails.protocolVersion = Constants.PROTOCOL_VERSION;
    if (isServer) {
        MapLayer collision =  map.
                getLayers().get("collision");
        for(MapObject object: collision.getObjects()) {
            worldManager.createWorldObject(object);
        }
        worldManager.addIncomingEvent(MessageObjectPool.instance.
                eventPool.obtain().set(State.RECEIVED, clientDetails));
    } else {
        client.sendTCP(clientDetails);
    }
    controls = new onScreenControls();
    
}
 
示例8
public void load(final World world, final BodyEditorLoader loader, final AssetManager assets, final MapLayer layer,
		final Object userData) {
	if (layer == null) {
		return;
	}

	for (MapObject mo : layer.getObjects()) {
		BodyDef bodyDefinition = new BodyDef();
		bodyDefinition.type = BodyType.KinematicBody;
		float x = ((Float) mo.getProperties().get("x")).floatValue() * unitScale;
		float y = ((Float) mo.getProperties().get("y")).floatValue() * unitScale;
		bodyDefinition.position.set(x, y);

		BodyFactory bodyFactory = null;
		Entity entity = null;

		if (CARROT_TYPE.equals(mo.getProperties().get(TYPE_PROPERTY, CARROT_TYPE, String.class))) {
			bodyFactory = new CarrotBodyFactory(loader);
			entity = EntityFactory.createCollectible(world, assets);
		} else {
			throw new IllegalArgumentException("Unknown collectible type {" + mo.getProperties().get(TYPE_PROPERTY, String.class) + "}");
		}

		Body body = bodyFactory.create(world, bodyDefinition);

		entity.setBody(body);
		body.setUserData(entity);
		collectibles.add(entity);
	}
}
 
示例9
public void createWorldObject(MapObject object) {
    worldBodyUtils.createWorldObject(object);
}
 
示例10
@Override
public void created(final Body body, final MapObject mapObject) {
	if (ENVIRONMENT_IDENTIFIER.equals(body.getUserData())) {
		this.body = body;
	}
}