com.badlogic.gdx.physics.box2d.FixtureDef Java Examples

The following examples show how to use com.badlogic.gdx.physics.box2d.FixtureDef. 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: ActorBuilder.java    From Bomberman_libGdx with MIT License 6 votes vote down vote up
public void createIndestructible(float x, float y, TextureAtlas tileTextureAtlas) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(x, y);

    Body body = b2dWorld.createBody(bodyDef);
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(0.5f, 0.5f);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = polygonShape;
    fixtureDef.filter.categoryBits = GameManager.INDESTRUCTIIBLE_BIT;
    fixtureDef.filter.maskBits = GameManager.PLAYER_BIT | GameManager.ENEMY_BIT | GameManager.BOMB_BIT;
    body.createFixture(fixtureDef);

    polygonShape.dispose();

    Renderer renderer = new Renderer(new TextureRegion(tileTextureAtlas.findRegion("indestructible"), 0, 0, 16, 16), 16 / GameManager.PPM, 16 / GameManager.PPM);
    renderer.setOrigin(16 / GameManager.PPM / 2, 16 / GameManager.PPM / 2);

    new EntityBuilder(world)
            .with(
                    new Transform(x, y, 1f, 1f, 0),
                    renderer
            )
            .build();
}
 
Example #2
Source File: Level15.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 150, 1124, boxWidth, 1352);
	int boxHeight = 30;
	createBox(world, fixtureDef, 354, 463, 403, boxHeight);
	for (int i = 0; i < 3; i++) {
		createBox(world, fixtureDef, 469, i * 358 + 841, 636, boxHeight);
	}
	createBox(world, fixtureDef, 548, 1785, 797, boxHeight);


	for (int i = 0; i < 3; i++) {
		createBox(world, fixtureDef, 605, i * 358 + 662, 636, boxHeight);
	}
	createBox(world, fixtureDef, 930, 947, boxWidth, 1415);
}
 
Example #3
Source File: Level12.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 534, 370, boxWidth, 742);

	createOpenCircle(world, fixtureDef, -83, 76, 375, 636, 961, 30);

	createOpenCircle(world, fixtureDef, -201, 115, 249, 640, 964, 20);

	createOpenCircle(world, fixtureDef, 180, 398, 113, 647, 964, 20);
	createOpenCircle(world, fixtureDef, 0, 175, 123, 411, 1048, 20);

	createBox(world, fixtureDef, 534, 1309, boxWidth, 698);
	int boxHeight = 30;
	createBox(world, fixtureDef, 411, 1654, 278, boxHeight);

	createBox(world, fixtureDef, 736, 1453, boxWidth, 282);
}
 
Example #4
Source File: Box2dLightTest.java    From box2dlights with Apache License 2.0 6 votes vote down vote up
private void createBoxes() {
	CircleShape ballShape = new CircleShape();
	ballShape.setRadius(RADIUS);

	FixtureDef def = new FixtureDef();
	def.restitution = 0.9f;
	def.friction = 0.01f;
	def.shape = ballShape;
	def.density = 1f;
	BodyDef boxBodyDef = new BodyDef();
	boxBodyDef.type = BodyType.DynamicBody;

	for (int i = 0; i < BALLSNUM; i++) {
		// Create the BodyDef, set a random position above the
		// ground and create a new body
		boxBodyDef.position.x = -20 + (float) (Math.random() * 40);
		boxBodyDef.position.y = 10 + (float) (Math.random() * 15);
		Body boxBody = world.createBody(boxBodyDef);
		boxBody.createFixture(def);
		balls.add(boxBody);
	}
	ballShape.dispose();
}
 
Example #5
Source File: Box2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
public Box2dSteeringEntity createSteeringEntity (World world, TextureRegion region, boolean independentFacing, int posX, int posY) {

		CircleShape circleChape = new CircleShape();
		circleChape.setPosition(new Vector2());
		int radiusInPixels = (int)((region.getRegionWidth() + region.getRegionHeight()) / 4f);
		circleChape.setRadius(Box2dSteeringTest.pixelsToMeters(radiusInPixels));

		BodyDef characterBodyDef = new BodyDef();
		characterBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(posX), Box2dSteeringTest.pixelsToMeters(posY));
		characterBodyDef.type = BodyType.DynamicBody;
		Body characterBody = world.createBody(characterBodyDef);

		FixtureDef charFixtureDef = new FixtureDef();
		charFixtureDef.density = 1;
		charFixtureDef.shape = circleChape;
		charFixtureDef.filter.groupIndex = 0;
		characterBody.createFixture(charFixtureDef);

		circleChape.dispose();

		return new Box2dSteeringEntity(region, characterBody, independentFacing, Box2dSteeringTest.pixelsToMeters(radiusInPixels));
	}
 
Example #6
Source File: Level18.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 212, 1081, boxWidth, 1678);

	int boxHeight = 30;
	for(int i = 0; i < 4; i++) {
		if(i == 0) {
			createBox(world, fixtureDef, 370, i * 385 + 257, 336, boxHeight);
		} else {
			createBox(world, fixtureDef, 385, i * 385 + 257, 366, boxHeight);
		}
	}

	for(int i = 0; i < 3; i++) {
		if(i == 0) {
			createBox(world, fixtureDef, 784, 498, 294, boxHeight);
		} else {
			createBox(world, fixtureDef, 694, i * 386 + 448, 456, boxHeight);
		}
	}
	createBox(world, fixtureDef, 652, 409, boxWidth, 177);
	createOpenCircle(world, fixtureDef, 180, 360, 225, 877, 336, 30);
	createBox(world, fixtureDef, 933, 955, boxWidth, 1279);
	createOpenCircle(world, fixtureDef, 0, 180, 225, 870, 1591, 30);
}
 
Example #7
Source File: Level09.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	//small circle
	createOpenCircle(world, fixtureDef, 270, 280.5f, 410, -18, 968, 5);
	createOpenCircle(world, fixtureDef, -51.5f, 90, 410, -18, 968, 40);

	//middle circle
	createOpenCircle(world, fixtureDef, -90, 67.5f, 688, -29, 999, 50);
	createOpenCircle(world, fixtureDef, 79, 90, 688, -29, 999, 10);

	//big circle
	createOpenCircle(world, fixtureDef, 270, 309, 904, -20, 999, 20);
	createOpenCircle(world, fixtureDef, -43, 90, 904, -20, 999, 50);

	createBox(world, fixtureDef, 540, 1904, 1080, 30);
}
 
Example #8
Source File: Level02.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	assertInitialized();

	// lines at an angle
	int boxWidth = 30;
	int rotation = 45;
	createBox(world, fixtureDef, 180, 454, boxWidth, 304, rotation);
	createBox(world, fixtureDef, 492, 675, boxWidth, 403, -rotation);
	createBox(world, fixtureDef, 180, 1058, boxWidth, 304, rotation);
	createBox(world, fixtureDef, 492, 1292, boxWidth, 403, -rotation);
	createBox(world, fixtureDef, 180, 1651, boxWidth, 304, rotation);

	// middle line
	createBox(world, fixtureDef, 635, 842, 30, 1685);

	// lines at the right
	int boxHeight = 30;
	createBox(world, fixtureDef, 1004, 562, 154, boxHeight);
	createBox(world, fixtureDef, 942, 1185, boxWidth, 1248);
}
 
Example #9
Source File: GravityAccelerometerSample.java    From Codelabs with MIT License 6 votes vote down vote up
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {

	/* Checks whether the max amount of balls were spawned */
	if (spawnedBalls < MAX_SPAWNED_BALLS) {
		spawnedBalls++;

		/* Translate camera point to world point */
		Vector3 unprojectedVector = new Vector3();
		camera.unproject(unprojectedVector.set(screenX, screenY, 0));

		/* Create a new ball */
		Shape shape = Box2DFactory.createCircleShape(1);
		FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
				0.25f, 0.75f, false);
		Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
				new Vector2(unprojectedVector.x, unprojectedVector.y));
	}

	return true;
}
 
Example #10
Source File: Level23.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 266, 343, boxWidth, 819, 45);
	createBox(world, fixtureDef, 266, 343, boxWidth, 819, -45);

	createBox(world, fixtureDef, 815, 345, boxWidth, 819, 45);
	createBox(world, fixtureDef, 957, 204, boxWidth, 418, -45);
	//--
	int boxHeight = 30;
	createBox(world, fixtureDef, 97, 1010, 191, boxHeight);

	createBox(world, fixtureDef, 541, 1010, boxWidth, 819, 45);
	createBox(world, fixtureDef, 633, 918, boxWidth, 1079, -45);

	createBox(world, fixtureDef, 986, 1010, 191, boxHeight);
	//--
	createBox(world, fixtureDef, 266, 1653, boxWidth, 819, 45);
	createBox(world, fixtureDef, 266, 1653, boxWidth, 819, -45);

	createBox(world, fixtureDef, 958, 1799, boxWidth, 414, 45);
	createBox(world, fixtureDef, 815, 1655, boxWidth, 819, -45);
}
 
Example #11
Source File: SpawnBodiesSample.java    From Codelabs with MIT License 6 votes vote down vote up
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {

	/* Checks whether the max amount of balls were spawned */
	if (spawnedBalls < MAX_SPAWNED_BALLS) {
		spawnedBalls++;

		/* Translate camera point to world point */
		Vector3 unprojectedVector = new Vector3();
		camera.unproject(unprojectedVector.set(screenX, screenY, 0));

		/* Create a new ball */
		Shape shape = Box2DFactory.createCircleShape(1);
		FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
				0.25f, 0.75f, false);
		Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
				new Vector2(unprojectedVector.x, unprojectedVector.y));
	}

	return true;
}
 
Example #12
Source File: Box2dRaycastObstacleAvoidanceTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private void createRandomWalls (int n) {
	PolygonShape groundPoly = new PolygonShape();

	BodyDef groundBodyDef = new BodyDef();
	groundBodyDef.type = BodyType.StaticBody;

	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = groundPoly;
	fixtureDef.filter.groupIndex = 0;

	walls = new Body[n];
	walls_hw = new int[n];
	walls_hh = new int[n];
	for (int i = 0; i < n; i++) {
		groundBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(MathUtils.random(50, (int)container.stageWidth - 50)),
			Box2dSteeringTest.pixelsToMeters(MathUtils.random(50, (int)container.stageHeight - 50)));
		walls[i] = world.createBody(groundBodyDef);
		walls_hw[i] = (int)MathUtils.randomTriangular(20, 150);
		walls_hh[i] = (int)MathUtils.randomTriangular(30, 80);
		groundPoly.setAsBox(Box2dSteeringTest.pixelsToMeters(walls_hw[i]), Box2dSteeringTest.pixelsToMeters(walls_hh[i]));
		walls[i].createFixture(fixtureDef);

	}
	groundPoly.dispose();
}
 
Example #13
Source File: CreateNearSensorSystem.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
protected void execute(List<SensorEntity> entities) {
    for (SensorEntity e : entities) {
        GameEntity gameEntity =  Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        RigidBody rigidBody = gameEntity.getRigidBody();
        NearSensor nearSensor = e.getNearSensor();

        if (nearSensor.distance > 0) {
            FixtureDef nearFixture = bodyBuilder.fixtureDefBuilder()
                    .circleShape(nearSensor.distance)
                    .sensor()
                    .build();
            rigidBody.body.createFixture(nearFixture).setUserData("NearSensor");

            if (nearSensor.resetDistance > nearSensor.distance) {
                FixtureDef nearResetFixture = bodyBuilder.fixtureDefBuilder()
                        .circleShape(nearSensor.resetDistance)
                        .sensor()
                        .build();
                rigidBody.body.createFixture(nearResetFixture).setUserData("ResetNearSensor");
            }
        }
    }

}
 
Example #14
Source File: Box2DFactory.java    From homescreenarcade with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
 * and rotating the box counterclockwise through the given angle, with specified restitution.
 */
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
        float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
    float hx = Math.abs((xmax - xmin) / 2);
    float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
    // Don't set the angle here; instead call setTransform on the body below. This allows future
    // calls to setTransform to adjust the rotation as expected.
    wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = wallshape;
    fdef.density = 1.0f;
    if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
    wall.setTransform(cx, cy, angle);
    return wall;
}
 
Example #15
Source File: NinjaRabbitBodyFactory.java    From ninja-rabbit with GNU General Public License v2.0 6 votes vote down vote up
public NinjaRabbitBodyFactory(final BodyEditorLoader loader) {
	if (loader == null) {
		throw new IllegalArgumentException("'loader' cannot be null");
	}
	this.loader = loader;

	bdef = new BodyDef();
	bdef.type = BodyType.DynamicBody;
	bdef.position.set(INITIAL_POSITION);
	bdef.fixedRotation = true;
	bdef.gravityScale = 2.0f;
	// bdef.bullet = true;

	fdef = new FixtureDef();
	fdef.density = 1.0f;
	fdef.restitution = 0.0f;
	fdef.friction = 0.8f;
}
 
Example #16
Source File: Scene2dRaycastObstacleAvoidanceTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private void createRandomWalls (int n) {
	PolygonShape groundPoly = new PolygonShape();

	BodyDef groundBodyDef = new BodyDef();
	groundBodyDef.type = BodyType.StaticBody;

	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = groundPoly;
	fixtureDef.filter.groupIndex = 0;

	walls = new Body[n];
	walls_hw = new int[n];
	walls_hh = new int[n];
	for (int i = 0; i < n; i++) {
		groundBodyDef.position.set(MathUtils.random(50, (int)container.stageWidth - 50),
			MathUtils.random(50, (int)container.stageHeight - 50));
		walls[i] = world.createBody(groundBodyDef);
		walls_hw[i] = (int)MathUtils.randomTriangular(20, 150);
		walls_hh[i] = (int)MathUtils.randomTriangular(30, 80);
		groundPoly.setAsBox(walls_hw[i], walls_hh[i]);
		walls[i].createFixture(fixtureDef);

	}
	groundPoly.dispose();
}
 
Example #17
Source File: FixtureAtlas.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** Creates and applies the fixtures defined in the editor. The name parameter is used to retrieve the shape from the loaded
 * binary file. Therefore, it _HAS_ to be the exact same name as the one that appeared. in the editor. <br/>
 * <br/>
 * 
 * WARNING: The body reference point is supposed to be the bottom left corner. As a result, calling "getPosition()" on the body
 * will return its bottom left corner. This is useful to draw a Sprite directly by setting its position to the body position. <br/>
 * <br/>
 * 
 * Also, saved shapes are normalized. Thus, you need to provide the desired width and height of your body for them to scale
 * according to your needs. <br/>
 * <br/>
 * 
 * Moreover, you can submit a custom FixtureDef object. Its parameters will be applied to every fixture applied to the body by
 * this method.
 * 
 * @param body A box2d Body, previously created.
 * @param name The name of the shape you want to load.
 * @param width The desired width of the body.
 * @param height The desired height of the body.
 * @param params Custom fixture parameters to apply. */
public void createFixtures (Body body, String name, float width, float height, FixtureDef params, Vector2 offset,
	Object userData) {
	BodyModel bm = bodyMap.get(name);
	if (bm == null) {
		Gdx.app.log("FixtureAtlas", name + " does not exist in the fixture list.");
	}

	Vector2[][] polygons = bm.getPolygons(width, height, offset);
	if (polygons == null) {
		Gdx.app.log("FixtureAtlas", name + " does not declare any polygon. "
			+ "Should not happen. Is your shape file corrupted ?");
	}

	for (Vector2[] polygon : polygons) {
		shape.set(polygon);
		FixtureDef fd = params == null ? DEFAULT_FIXTURE : params;
		fd.shape = shape;
		Fixture f = body.createFixture(fd);
		f.setUserData(userData);
	}
}
 
Example #18
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Body createBoxBody(final PhysicsWorld pPhysicsWorld, final IEntity pEntity, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final float[] sceneCenterCoordinates = pEntity.getSceneCenterCoordinates();
	final float centerX = sceneCenterCoordinates[Constants.VERTEX_INDEX_X];
	final float centerY = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y];
	return PhysicsFactory.createBoxBody(pPhysicsWorld, centerX, centerY, pEntity.getWidthScaled(), pEntity.getHeightScaled(), pEntity.getRotation(), pBodyType, pFixtureDef, pPixelToMeterRatio);
}
 
Example #19
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
public static FixtureDef createFixtureDef(final float pDensity, final float pElasticity, final float pFriction, final boolean pSensor, final short pCategoryBits, final short pMaskBits, final short pGroupIndex) {
	final FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.density = pDensity;
	fixtureDef.restitution = pElasticity;
	fixtureDef.friction = pFriction;
	fixtureDef.isSensor = pSensor;
	final Filter filter = fixtureDef.filter;
	filter.categoryBits = pCategoryBits;
	filter.maskBits = pMaskBits;
	filter.groupIndex = pGroupIndex;
	return fixtureDef;
}
 
Example #20
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
public static Body createLineBody(final PhysicsWorld pPhysicsWorld, final Line pLine, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final float[] sceneCoordinates = pLine.convertLocalCoordinatesToSceneCoordinates(0, 0);
	final float x1 = sceneCoordinates[Constants.VERTEX_INDEX_X];
	final float y1 = sceneCoordinates[Constants.VERTEX_INDEX_Y];

	pLine.convertLocalCoordinatesToSceneCoordinates(pLine.getX2() - pLine.getX1(), pLine.getY2() - pLine.getY1());
	final float x2 = sceneCoordinates[Constants.VERTEX_INDEX_X];
	final float y2 = sceneCoordinates[Constants.VERTEX_INDEX_Y];

	return PhysicsFactory.createLineBody(pPhysicsWorld, x1, y1, x2, y2, pFixtureDef, pPixelToMeterRatio);
}
 
Example #21
Source File: Level14.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 220, 1010, boxWidth, 1298);
	createBox(world, fixtureDef, 457, 987, boxWidth, 1342);
	createBox(world, fixtureDef, 676, 944, boxWidth, 1424);
	createBox(world, fixtureDef, 806, 881, boxWidth, 1045);
	createBox(world, fixtureDef, 935, 1016, boxWidth, 1315);

	int boxHeight = 30;
	createBox(world, fixtureDef, 577, 1659, 743, boxHeight);
}
 
Example #22
Source File: AbstractGameLevel.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void createWave(PhysicsWorld world, FixtureDef fixtureDef, float amplitude, float frequency,
                          float x, float y, float waveLength, float waveStart) {
    float steps = 100;
    for (int i = 0; i < steps; i++) {
        float angle = 2 * (float) Math.PI * frequency * (i + waveStart) / steps;
        float sin = (float) Math.sin(angle);

        createBox(world, fixtureDef, x + waveLength * (i / steps), y - amplitude * sin, 3, 40);
    }
}
 
Example #23
Source File: AbstractGameLevel.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void createOpenCircleBody(PhysicsWorld world, FixtureDef fixtureDef, float startAngle, float endAngle,
                                    float radius, float innerRadius, float centerX, float centerY, int segmentCount) {
    float angleStep = (endAngle - startAngle) / (float) segmentCount;
    float curAngle = startAngle + angleStep / 2;
    float width = 3;
    float height = (radius - innerRadius);
    float x;
    float y;
    float angleRad;
    float radiusCorrection = (float) Math.cos(angleStep * DEG2RAD / 2);

    while (curAngle < endAngle) {
        float angleLeft = (curAngle - angleStep / 2) * DEG2RAD;
        float xLeft = centerX + radius * (float) Math.cos(angleLeft);
        float yLeft = centerY + radius * (float) Math.sin(angleLeft);

        float angleRight = (curAngle + angleStep / 2) * DEG2RAD;
        float xRight = centerX + radius * (float) Math.cos(angleRight);
        float yRight = centerY + radius * (float) Math.sin(angleRight);

        float dx = xRight - xLeft;
        float dy = yRight - yLeft;
        width = height / segmentCount + (float) (Math.sqrt(dx * dx + dy * dy));

        angleRad = curAngle * DEG2RAD;
        x = centerX + (radius * radiusCorrection) * (float) Math.cos(angleRad);
        y = centerY + (radius * radiusCorrection) * (float) Math.sin(angleRad);
        createBoxBody(world, fixtureDef, x, y, width, height, 90 - curAngle);

        curAngle += angleStep;
    }
}
 
Example #24
Source File: PractiseLevel.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createBox(world, fixtureDef, _originalWidth / 2, _originalHeight, _originalWidth, 5);
	createBox(world, fixtureDef, _originalWidth / 2, 0, _originalWidth, 5);
	createBox(world, fixtureDef, 0, _originalHeight / 2, 5, _originalHeight);
	createBox(world, fixtureDef, _originalWidth, _originalHeight / 2, 5, _originalHeight);

	_centerSensor = PhysicsFactory.createCircleBody(world, _scale * _originalWidth / 2, _scale * _originalHeight / 2, .1f * _width,
			BodyDef.BodyType.StaticBody, WorldController.SENSOR_FIX_DEF);
	_centerSensor.setUserData(ObjectName.CENTER_SENSOR_NAME);
}
 
Example #25
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Body createCircleBody(final PhysicsWorld pPhysicsWorld, final IEntity pEntity, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final float[] sceneCenterCoordinates = pEntity.getSceneCenterCoordinates();
	final float centerX = sceneCenterCoordinates[Constants.VERTEX_INDEX_X];
	final float centerY = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y];
	return PhysicsFactory.createCircleBody(pPhysicsWorld, centerX, centerY, pEntity.getWidthScaled() * 0.5f, pEntity.getRotation(), pBodyType, pFixtureDef, pPixelToMeterRatio);
}
 
Example #26
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
public static FixtureDef createFixtureDef(final float pDensity, final float pElasticity, final float pFriction, final boolean pSensor) {
	final FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.density = pDensity;
	fixtureDef.restitution = pElasticity;
	fixtureDef.friction = pFriction;
	fixtureDef.isSensor = pSensor;
	return fixtureDef;
}
 
Example #27
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * @param pPhysicsWorld
 * @param pEntity
 * @param pTriangleVertices are to be defined relative to the center of the pEntity and have the {@link PhysicsConstants#PIXEL_TO_METER_RATIO_DEFAULT} applied.
 * 					The vertices will be triangulated and for each triangle a {@link Fixture} will be created.
 * @param pBodyType
 * @param pFixtureDef
 * @return
 */
public static Body createTrianglulatedBody(final PhysicsWorld pPhysicsWorld, final IEntity pEntity, final List<Vector2> pTriangleVertices, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final Vector2[] TMP_TRIANGLE = new Vector2[3];

	final BodyDef boxBodyDef = new BodyDef();
	boxBodyDef.type = pBodyType;

	final float[] sceneCenterCoordinates = pEntity.getSceneCenterCoordinates();
	boxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] / pPixelToMeterRatio;
	boxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] / pPixelToMeterRatio;

	final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

	final int vertexCount = pTriangleVertices.size();
	for (int i = 0; i < vertexCount; /* */) {
		final PolygonShape boxPoly = new PolygonShape();

		TMP_TRIANGLE[2] = pTriangleVertices.get(i++);
		TMP_TRIANGLE[1] = pTriangleVertices.get(i++);
		TMP_TRIANGLE[0] = pTriangleVertices.get(i++);

		boxPoly.set(TMP_TRIANGLE);
		pFixtureDef.shape = boxPoly;

		boxBody.createFixture(pFixtureDef);

		boxPoly.dispose();
	}

	return boxBody;
}
 
Example #28
Source File: Level08.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createOpenCircle(world, fixtureDef, -57, 88, 890, 173, 1030, 35);
	createOpenCircle(world, fixtureDef, -56, 110, 625, 190, 1004, 30);

	createBox(world, fixtureDef, 15, 1766, 30, 308);
	createBox(world, fixtureDef, 177, 1908, 326, 30);

	createOpenCircle(world, fixtureDef, -60, 78, 458, 110, 989, 20);
	createOpenCircle(world, fixtureDef, 147, 257, 500, 662, 976, 20);
}
 
Example #29
Source File: Level03.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	Vector2 center = Vector2Pool.obtain(541, 942);

	createOpenCircle(world, fixtureDef, -70, 250, 133, center.x, center.y, 20);
	createOpenCircle(world, fixtureDef, 103, 438.5f, 262, center.x, center.y, 30);
	createOpenCircle(world, fixtureDef, -81, 260, 395, center.x, center.y, 40);
}
 
Example #30
Source File: Level21.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createOpenCircle(world, fixtureDef, -90, 90, 580, 0, 878, 35);

	createOpenCircle(world, fixtureDef, 90, 270, 300, 1080, 1299, 30);
	createOpenCircle(world, fixtureDef, 180, 360, 300, 497, 1920, 30);
}