List of usage examples for com.badlogic.gdx.physics.box2d Body setFixedRotation
public void setFixedRotation(boolean flag)
From source file:com.hatstick.fireman.physics.Box2DPhysicsWorld.java
License:Apache License
private Fixture createPhysicsObject(Rectangle bounds, ModelType type, Integer id) { UserData userData = new UserData(numEnterPoints, type, null); CircleShape objectPoly = new CircleShape(); objectPoly.setRadius(bounds.width / 2); BodyDef enemyBodyDef = new BodyDef(); enemyBodyDef.type = BodyType.DynamicBody; enemyBodyDef.position.x = bounds.x;/*from w w w .ja va2 s. co m*/ enemyBodyDef.position.y = bounds.y; Body objectBody = world.createBody(enemyBodyDef); FixtureDef objectFixtureDef = new FixtureDef(); objectFixtureDef.shape = objectPoly; // objectBody.setUserData(userData); objectFixtureDef.restitution = .025f; Fixture fixture = objectBody.createFixture(objectFixtureDef); fixture.setUserData(userData); objectBody.setLinearDamping(2f); objectBody.setGravityScale(.4f); objectBody.setFixedRotation(true); objectPoly.dispose(); numEnterPoints++; //add a sensor on the bottom to check if touching ground (for jumping) PolygonShape polygonShape = new PolygonShape(); polygonShape.setAsBox(bounds.width / 3, bounds.height / 8, new Vector2(0, -bounds.height / 2), 0); objectFixtureDef = new FixtureDef(); objectFixtureDef.shape = polygonShape; objectFixtureDef.isSensor = true; Fixture footSensorFixture = objectBody.createFixture(objectFixtureDef); footSensorFixture.setUserData(new UserData(numEnterPoints, ModelType.FOOT_SENSOR, id)); //add a sensor on left side to check if touching wall (for grappling) PolygonShape polygonShape2 = new PolygonShape(); polygonShape2.setAsBox(bounds.width / 8, bounds.height / 3, new Vector2(-bounds.width / 2, 0), 0); objectFixtureDef = new FixtureDef(); objectFixtureDef.shape = polygonShape2; objectFixtureDef.isSensor = true; Fixture leftSideSensorFixture = objectBody.createFixture(objectFixtureDef); leftSideSensorFixture.setUserData(new UserData(numEnterPoints, ModelType.LEFT_SIDE_SENSOR, id)); //add a sensor on right side to check if touching wall (for grappling) polygonShape2.setAsBox(bounds.width / 8, bounds.height / 3, new Vector2(bounds.width / 2, 0), 0); objectFixtureDef = new FixtureDef(); objectFixtureDef.shape = polygonShape2; objectFixtureDef.isSensor = true; Fixture rightSideSensorFixture = objectBody.createFixture(objectFixtureDef); rightSideSensorFixture.setUserData(new UserData(numEnterPoints, ModelType.RIGHT_SIDE_SENSOR, id)); return fixture; }
From source file:Helper.WorldUtils.java
public static Body createPinguin(World world) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y)); Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2, body.getLocalCenter(), 0); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;//from www .j a v a2s .c o m fixtureDef.density = 0.0f; fixtureDef.friction = BuffsInfo.getFrictionBuff().getPower(); fixtureDef.restitution = 0.35f; body.createFixture(fixtureDef); //body.resetMassData(); body.getFixtureList().get(0).setUserData("PINGUIN"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
public static Body createSnake(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.position.set(new Vector2(x, y + height)); // bodyDef.active = false; Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;//from w w w . j a v a 2 s. co m fixtureDef.density = 0.0f; fixtureDef.friction = 1.8f; fixtureDef.restitution = 0.35f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("SNAKE"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
public static Body createAntelopeBack(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(x, y + height)); // bodyDef.active = false; Body body = world.createBody(bodyDef); body.setGravityScale(0f);// www .j a v a 2 s. c om body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box; fixtureDef.density = 0.0f; fixtureDef.friction = 1.8f; fixtureDef.restitution = 0f; body.createFixture(fixtureDef); body.getFixtureList().get(0).setUserData("AntelopeBack"); body.resetMassData(); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
public static Body createAntelopeBody(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(x, y + height)); Body body = world.createBody(bodyDef); body.setGravityScale(0f);/*from w ww .j a v a 2s.co m*/ body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box; fixtureDef.density = 1.0f; fixtureDef.friction = 1.8f; fixtureDef.restitution = 0f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("AntelopeBody"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
public static Body createHippoHead(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.position.set(new Vector2(x, y + height / 2)); // bodyDef.active = false; Body body = world.createBody(bodyDef); body.setGravityScale(0f);/*from w w w. j av a 2 s .co m*/ body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box; fixtureDef.density = 0.0f; fixtureDef.friction = 1.8f; fixtureDef.restitution = 0f; body.createFixture(fixtureDef); body.getFixtureList().get(0).setUserData("HippoHead"); body.resetMassData(); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
public static Body createHippoBody(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.position.set(new Vector2(x, y + height / 2)); Body body = world.createBody(bodyDef); body.setGravityScale(0f);/*w w w. ja v a 2s . co m*/ body.setFixedRotation(false); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box; fixtureDef.density = 1.0f; fixtureDef.friction = 1.8f; fixtureDef.restitution = 0f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("HippoBody"); box.dispose(); return body; }
From source file:me.scarlet.undertailor.collision.bbshapes.BoundingCircle.java
License:Open Source License
@Override public void applyFixture(Body body) { if (this.targetBody == body || !this.hasTarget()) { this.targetBody = body; if (lastFixture != null && body.getFixtureList().contains(lastFixture, true)) { body.destroyFixture(lastFixture); }//w w w . j ava 2 s.c om if (this.canCollide()) { body.setFixedRotation(fixedRotation); CircleShape circle = new CircleShape(); circle.setPosition(this.getOffset()); circle.setRadius(radius * this.getScale()); body.createFixture(circle, 0.5F); circle.dispose(); } } }