com.badlogic.gdx.maps.objects.RectangleMapObject Java Examples

The following examples show how to use com.badlogic.gdx.maps.objects.RectangleMapObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BattleMap.java    From Norii with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #2
Source File: GameWorld.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private void createLights () {
		if (!mapUtils.hasObjectGroup(ObjectGroup.Lights)) {
			this.nightMode = false;
			return;
		}

		float rttScale = 0.5f;
		int maxRays = 360;

		if (!URacer.Game.isDesktop()) {
			rttScale = 0.2f;
			maxRays = 360;
		}

		RayHandler.setColorPrecisionHighp();

		rayHandler = new RayHandler(box2dWorld, maxRays, (int)(ScaleUtils.PlayWidth * rttScale),
			(int)(ScaleUtils.PlayHeight * rttScale), true);
		rayHandler.setShadows(true);
		rayHandler.setCulling(true);
		rayHandler.setBlur(true);
		rayHandler.setBlurNum(2);
		rayHandler.setAmbientLight(0.1f, 0.05f, 0.1f, 0.4f);

		final Color c = new Color();

		// setup player headlights data
		c.set(0.1f, 0.2f, 0.9f, 0.85f);

		int headlightsMask = CollisionFilters.CategoryTrackWalls;
		// int headlightsMask = CollisionFilters.CategoryTrackWalls | CollisionFilters.CategoryReplay;
		// int headlightsMask = CollisionFilters.CategoryReplay;
		// int headlightsMask = 0;

		playerHeadlightsA = new ConeLight(rayHandler, maxRays, c, 25, 0, 0, 0, 9);
		playerHeadlightsA.setSoft(true);
		playerHeadlightsA.setMaskBits(headlightsMask);

		playerHeadlightsB = new ConeLight(rayHandler, maxRays, c, 25, 0, 0, 0, 9);
		playerHeadlightsB.setSoft(true);
		playerHeadlightsB.setMaskBits(headlightsMask);

		// setup level lights data, if any
		Vector2 pos = new Vector2();
		MapLayer group = mapUtils.getObjectGroup(ObjectGroup.Lights);

		int lights_count = group.getObjects().getCount();
		lights = new PointLight[lights_count];

		for (int i = 0; i < lights_count; i++) {
			//@off
			c.set(
//			 MathUtils.random(0,1),
//			 MathUtils.random(0,1),
//			 MathUtils.random(0,1),
							1f, .85f, 0.6f, 0.8f
//				MathUtils.random(0.85f,1),
//				MathUtils.random(0.8f,0.85f),
//				MathUtils.random(0.6f,0.8f),
//				0.55f
			);
			//@on

			RectangleMapObject o = (RectangleMapObject)group.getObjects().get(i);
			pos.set(o.getRectangle().x, o.getRectangle().y);// .scl(scalingStrategy.invTileMapZoomFactor);
			pos.y = worldSizePx.y - pos.y;
			pos.set(Convert.px2mt(pos));// .scl(scalingStrategy.tileMapZoomFactor);

			PointLight l = new PointLight(rayHandler, maxRays, c, MathUtils.random(15, 20), pos.x, pos.y);
			l.setSoft(true);
			l.setStaticLight(false);
			l.setMaskBits(CollisionFilters.CategoryPlayer | CollisionFilters.CategoryTrackWalls);

			lights[i] = l;
		}

		// playerImpulse = new PointLight(rayHandler, maxRays);
		// playerImpulse.setMaskBits(CollisionFilters.CategoryPlayer | CollisionFilters.CategoryReplay);
		// playerImpulse.setSoft(true);
		// playerImpulse.setStaticLight(false);
		// playerImpulse.setActive(true);
		// playerImpulse.setColor(1, 1, 1, 1f);
		// playerImpulse.setDistance(5);
	}
 
Example #3
Source File: GameWorld.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private List<TreeStillModel> createTrees () {
	List<TreeStillModel> models = null;

	if (mapUtils.hasObjectGroup(ObjectGroup.Trees)) {

		// We want to differentiate tree meshes as much as we can
		// rotation will helps immensely, but non-orthogonal rotations
		// will cause the bounding box to get recomputed only approximately
		// thus loosing precision: orthogonal rotations instead provides
		// high
		// quality AABB recomputation.
		//
		// We still have 4 variations for any given tree!
		treeRotations[0] = 0;
		treeRotations[1] = 90;
		treeRotations[2] = 180;
		treeRotations[3] = 270;

		MathUtils.random.setSeed(Long.MAX_VALUE);
		MapLayer group = mapUtils.getObjectGroup(ObjectGroup.Trees);

		if (group.getObjects().getCount() > 0) {

			models = new ArrayList<TreeStillModel>(group.getObjects().getCount());

			for (int i = 0; i < group.getObjects().getCount(); i++) {
				RectangleMapObject o = (RectangleMapObject)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));
				}

				TreeStillModel model = null;
				if (o.getProperties().get("type") != null) {
					//@off
					model = ModelFactory.createTree(
						o.getProperties().get("type", String.class),
						o.getRectangle().x,
						worldSizePx.y - o.getRectangle().y,
						scale);
					//@on
				} else {
					Gdx.app.log("TrackTrees", "Load error, no type was given for the tree #" + (i + 1));
				}

				if (model != null) {
					// model.setRotation( MathUtils.random( -180f, 180f ),
					// 0, 0, 1f );
					model.setRotation(treeRotations[MathUtils.random(0, 3)], 0, 0, 1f);
					models.add(nextIndexForTrees(models, model), model);
				}
			}
		}
	}

	return models;
}