List of usage examples for com.badlogic.gdx.physics.box2d Body resetMassData
public void resetMassData()
From source file:com.gamestudio24.martianrun.utils.WorldUtils.java
License:Apache License
public static Body createRunner(World world) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y)); PolygonShape shape = new PolygonShape(); shape.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2); Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); body.createFixture(shape, Constants.RUNNER_DENSITY); body.resetMassData(); body.setUserData(new RunnerUserData(Constants.RUNNER_WIDTH, Constants.RUNNER_HEIGHT)); shape.dispose();//from w w w . j ava 2s .c o m return body; }
From source file:com.gamestudio24.martianrun.utils.WorldUtils.java
License:Apache License
public static Body createEnemy(World world) { EnemyType enemyType = RandomUtils.getRandomEnemyType(); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(new Vector2(enemyType.getX(), enemyType.getY())); PolygonShape shape = new PolygonShape(); shape.setAsBox(enemyType.getWidth() / 2, enemyType.getHeight() / 2); Body body = world.createBody(bodyDef); body.createFixture(shape, enemyType.getDensity()); body.resetMassData(); EnemyUserData userData = new EnemyUserData(enemyType.getWidth(), enemyType.getHeight(), enemyType.getAnimationAssetId()); body.setUserData(userData);//from w w w . j a v a 2 s .c o m shape.dispose(); return body; }
From source file:es.eucm.ead.engine.gameobjects.effects.PhysicsEffectGO.java
License:Open Source License
public static void createBody(World world, SceneElement e, ValueMap valueMap) { float x = valueMap.getValue(e, SceneElement.VAR_X, 0f) / WORLD_SCALE; float y = valueMap.getValue(e, SceneElement.VAR_Y, 0f) / WORLD_SCALE; float width = valueMap.getValue(e, SceneElement.VAR_WIDTH, 1) / WORLD_SCALE; float height = valueMap.getValue(e, SceneElement.VAR_HEIGHT, 1) / WORLD_SCALE; // TODO what if corner is not center? PhType phType = valueMap.getValue(e, PhysicsEf.VAR_PH_TYPE, PhType.DYNAMIC); PhShape phShape = valueMap.getValue(e, PhysicsEf.VAR_PH_SHAPE, PhShape.RECTANGULAR); Shape s = null;// w w w . ja v a 2 s . c om switch (phShape) { case CIRCULAR: s = new CircleShape(); s.setRadius(width / 2); break; default: s = new PolygonShape(); ((PolygonShape) s).setAsBox(width / 2, height / 2); } BodyDef bd = new BodyDef(); switch (phType) { case STATIC: bd.type = BodyType.StaticBody; break; case DYNAMIC: bd.type = BodyType.DynamicBody; break; } bd.position.set(x, y); bd.angle = valueMap.getValue(e, SceneElement.VAR_ROTATION, 0f); FixtureDef fixture = new FixtureDef(); fixture.shape = s; fixture.density = valueMap.getValue(e, PhysicsEf.VAR_PH_DENSITY, 1f); fixture.friction = valueMap.getValue(e, PhysicsEf.VAR_PH_FRICTION, 1f); fixture.restitution = valueMap.getValue(e, PhysicsEf.VAR_PH_RESTITUTION, 1f); Body body = world.createBody(bd); body.createFixture(fixture); body.resetMassData(); valueMap.setValue(e.getId(), VAR_PH_BODY, body); }
From source file:Helper.WorldUtils.java
public static Body createStopObj(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); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;/*from w w w. j ava2 s .c om*/ fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.5f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("STOPOBJ"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
private static Body getFoliageBody(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)); Body body = world.createBody(bodyDef); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;/*from w ww . j ava2s . c o m*/ fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.4f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("FOLIAGEBODY"); box.dispose(); Foliage = body; return body; }
From source file:Helper.WorldUtils.java
private static Body getStemBody(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)); Body body = world.createBody(bodyDef); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;//from w ww .j av a 2 s. c o m fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.4f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("STEMBODY"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
private static Body getGiraffeBody(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)); Body body = world.createBody(bodyDef); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;// w w w. ja v a2 s . co m fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.0f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("GIRAFFEBODY"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
private static Body getGiraffeNeck(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)); Body body = world.createBody(bodyDef); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;/*from w w w. j a v a2s . com*/ fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.0f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("GIRAFFENECK"); box.dispose(); return body; }
From source file:Helper.WorldUtils.java
private static Body getGiraffeHead(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)); Body body = world.createBody(bodyDef); PolygonShape box = new PolygonShape(); box.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = box;//w w w .j a va 2 s . c o m fixtureDef.density = 0.0f; fixtureDef.friction = 0.0f; fixtureDef.restitution = 0.0f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("GIRAFFEHEAD"); box.dispose(); GiraffeHead = body; 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);//www .j av a 2 s . c o m 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 = 0.35f; body.createFixture(fixtureDef); body.resetMassData(); body.getFixtureList().get(0).setUserData("SNAKE"); box.dispose(); return body; }