Example usage for com.badlogic.gdx.physics.box2d World createBody

List of usage examples for com.badlogic.gdx.physics.box2d World createBody

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d World createBody.

Prototype

public Body createBody(BodyDef def) 

Source Link

Document

Create a rigid body given a definition.

Usage

From source file:be.ac.ucl.lfsab1509.bouboule.game.body.GameBody.java

License:Open Source License

/**
 * Generical constructor for bodies. ( circle, rectangle or jsonFiled )
 * Arguments ://w w w  .  j a  v a2  s  . com
 * @param width       : width of a rectangle object
 * @param height      : height of a rectangle object
 * @param radius      : radius of a circle object
 * @param bodyType      : Static or Dynamic
 * @param density      : Mass in [kg] of the body
 * @param elasticity   : define the elastical property of Bouboul [0..1]f
 * @param sensor      : true/false
 * @param pos         : initial position
 * @param angle         : initial rotated angle
 * @param jsonFile      : path to the jsonFile
 * @param jsonName      : name of the jsonFile (must match the json file attribute) 
 * @param size         : size in pixel of the image to match the object
 * 
 * 
 * MakeBody(float width, float height,float radius,BodyDef.BodyType bodyType,
 *    float density,float elasticity,boolean sensor, Vector2 pos,float angle, 
 *    String jsonFile, String jsonName, float size)
 */
public void MakeBody(final float width, final float height, final float radius, final BodyDef.BodyType bodyType,
        final float density, final float elasticity, final boolean sensor, final Vector2 pos, final float angle,
        final String jsonFile, final String jsonName, final float size) {

    World world = GraphicManager.getWorld();

    //Set up of a body that has a physical interpretation
    BodyDef bodyDef = new BodyDef();

    bodyDef.type = bodyType;
    bodyDef.angle = angle;
    bodyDef.position.set(GraphicManager.convertToGame(pos.x), GraphicManager.convertToGame(pos.y));
    //dont forget to use the game dimension instead of real world dimension

    //Storage in the main variable
    body = world.createBody(bodyDef);

    if (jsonFile.isEmpty()) {
        /*if (radius == 0)
           makeRectBody(width, height, bodyType, density, elasticity, sensor, pos, angle);
        else*/
        makeCircleBody(radius, bodyType, density, elasticity, sensor, pos, angle);
    } else {
        makeJsonBody(bodyType, density, elasticity, sensor, pos, angle, jsonFile, jsonName, size);
    }

    //Set up of the Vector2 that define the object durection
    positionVector.set(GraphicManager.convertToWorld(body.getPosition().x),
            GraphicManager.convertToWorld(body.getPosition().y));

}

From source file:ch.coldpixel.mario.Sprites.InteractiveTileObject.java

public InteractiveTileObject(World world, TiledMap map, Rectangle bounds) {
    this.world = world;
    this.map = map;
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / MarioBros.PPM,
            (bounds.getY() + bounds.getHeight() / 2) / MarioBros.PPM);

    body = world.createBody(bdef);

    shape.setAsBox(bounds.getWidth() / 2 / MarioBros.PPM, bounds.getHeight() / 2 / MarioBros.PPM);
    fdef.shape = shape;/*from w ww  .  ja v a2  s .  c  o m*/
    body.createFixture(fdef);

}

From source file:ch.coldpixel.mario.Tools.B2WorldCreator.java

public B2WorldCreator(World world, TiledMap map) {
    //Create body and fixture variables
    BodyDef bdef = new BodyDef();
    PolygonShape shape = new PolygonShape();
    FixtureDef fdef = new FixtureDef();
    Body body;//from   ww w.jav  a 2s .c om

    //create ground bodies/fixture
    for (MapObject object : map.getLayers().get(2).getObjects().getByType(RectangleMapObject.class)) { //get(2) = in TILED from below the 2nd object(starts with 0, so it gets ground)
        Rectangle rect = ((RectangleMapObject) object).getRectangle(); //Get Rectangle Object itself

        bdef.type = BodyDef.BodyType.StaticBody;//3 different bodys, static=selfexplaining, dynamic=typical player, kinematic=not effected by forces like gravity, but can manipulated with velocity, ex: moving plattforms
        bdef.position.set((rect.getX() + rect.getWidth() / 2) / MarioBros.PPM,
                (rect.getY() + rect.getHeight() / 2) / MarioBros.PPM);

        body = world.createBody(bdef);//add body to our world

        shape.setAsBox(rect.getWidth() / 2 / MarioBros.PPM, rect.getHeight() / 2 / MarioBros.PPM);
        fdef.shape = shape;
        body.createFixture(fdef);
    }

    //create pipe bodies/fixture
    for (MapObject object : map.getLayers().get(3).getObjects().getByType(RectangleMapObject.class)) {
        Rectangle rect = ((RectangleMapObject) object).getRectangle();

        bdef.type = BodyDef.BodyType.StaticBody;
        bdef.position.set((rect.getX() + rect.getWidth() / 2) / MarioBros.PPM,
                (rect.getY() + rect.getHeight() / 2) / MarioBros.PPM);

        body = world.createBody(bdef);

        shape.setAsBox(rect.getWidth() / 2 / MarioBros.PPM, rect.getHeight() / 2 / MarioBros.PPM);
        fdef.shape = shape;
        body.createFixture(fdef);
    }

    //create brick bodies/fixture
    for (MapObject object : map.getLayers().get(5).getObjects().getByType(RectangleMapObject.class)) {
        Rectangle rect = ((RectangleMapObject) object).getRectangle();

        new Brick(world, map, rect);

    }

    //create coin bodies/fixtures
    for (MapObject object : map.getLayers().get(4).getObjects().getByType(RectangleMapObject.class)) {
        Rectangle rect = ((RectangleMapObject) object).getRectangle();

        new Coin(world, map, rect);

    }

}

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

@SuppressWarnings("unused")
public static Body createStaticBox(World world, float x, float y, float width, float height) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(x + width / 2, y + height / 2);
    Body body = world.createBody(bodyDef);

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);

    body.createFixture(shape, 1);/*from  ww w .  j  a v a 2  s. co m*/
    return body;
}

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

public static Body createStaticBodyForMapObject(World world, MapObject object) {
    final float u = Constants.UNIT_FOR_PIXEL;
    float rotation = object.getProperties().get("rotation", 0f, Float.class);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.angle = -rotation * MathUtils.degreesToRadians;

    if (object instanceof RectangleMapObject) {
        Rectangle rect = ((RectangleMapObject) object).getRectangle();

        /*//from w  w w  .j a  va  2  s  .  c o  m
          A          D
           x--------x
           |        |
           x--------x
          B          C
         */
        float[] vertices = new float[8];
        // A
        vertices[0] = 0;
        vertices[1] = 0;
        // B
        vertices[2] = 0;
        vertices[3] = -rect.getHeight();
        // C
        vertices[4] = rect.getWidth();
        vertices[5] = -rect.getHeight();
        // D
        vertices[6] = rect.getWidth();
        vertices[7] = 0;
        scaleVertices(vertices, u);

        bodyDef.position.set(u * rect.getX(), u * (rect.getY() + rect.getHeight()));
        Body body = world.createBody(bodyDef);

        PolygonShape shape = new PolygonShape();
        shape.set(vertices);

        body.createFixture(shape, 1);
        return body;
    } else if (object instanceof PolygonMapObject) {
        Polygon polygon = ((PolygonMapObject) object).getPolygon();
        float[] vertices = polygon.getVertices().clone();
        scaleVertices(vertices, u);

        bodyDef.position.set(polygon.getX() * u, polygon.getY() * u);
        Body body = world.createBody(bodyDef);

        PolygonShape shape = new PolygonShape();
        shape.set(vertices);

        body.createFixture(shape, 1);
        return body;
    } else if (object instanceof EllipseMapObject) {
        Ellipse ellipse = ((EllipseMapObject) object).getEllipse();
        float radius = ellipse.width * u / 2;
        float x = ellipse.x * u + radius;
        float y = ellipse.y * u + radius;

        bodyDef.position.set(x, y);
        Body body = world.createBody(bodyDef);

        CircleShape shape = new CircleShape();
        shape.setRadius(radius);

        body.createFixture(shape, 1);
        return body;
    }
    throw new RuntimeException("Unsupported MapObject type: " + object);
}

From source file:com.altportalgames.colorrain.utils.TiledMapHelper.java

License:Apache License

/**
 * Reads a file describing the collision boundaries that should be set
 * per-tile and adds static bodies to the boxd world.
 * /*from  w  w  w.  j  ava 2s . c o  m*/
 * @param collisionsFile
 * @param world
 * @param pixelsPerMeter
 *            the pixels per meter scale used for this world
 */
public void loadCollisions(String collisionsFile, World world, float pixelsPerMeter) {
    System.out.println("tilewidth " + getMap().height);
    /**
     * Detect the tiles and dynamically create a representation of the map
     * layout, for collision detection. Each tile has its own collision
     * rules stored in an associated file.
     * 
     * The file contains lines in this format (one line per type of tile):
     * tileNumber XxY,XxY XxY,XxY
     * 
     * Ex:
     * 
     * 3 0x0,31x0 ... 4 0x0,29x0 29x0,29x31
     * 
     * For a 32x32 tileset, the above describes one line segment for tile #3
     * and two for tile #4. Tile #3 has a line segment across the top. Tile
     * #1 has a line segment across most of the top and a line segment from
     * the top to the bottom, 30 pixels in.
     */

    FileHandle fh = Gdx.files.internal(collisionsFile);
    String collisionFile = fh.readString();
    String lines[] = collisionFile.split("\\r?\\n");

    HashMap<Integer, ArrayList<LineSegment>> tileCollisionJoints = new HashMap<Integer, ArrayList<LineSegment>>();

    /**
     * Some locations on the map (perhaps most locations) are "undefined",
     * empty space, and will have the tile type 0. This code adds an empty
     * list of line segments for this "default" tile.
     */
    tileCollisionJoints.put(Integer.valueOf(0), new ArrayList<LineSegment>());

    for (int n = 0; n < lines.length; n++) {
        String cols[] = lines[n].split(" ");
        int tileNo = Integer.parseInt(cols[0]);

        ArrayList<LineSegment> tmp = new ArrayList<LineSegment>();

        for (int m = 1; m < cols.length; m++) {
            String coords[] = cols[m].split(",");

            String start[] = coords[0].split("x");
            String end[] = coords[1].split("x");

            tmp.add(new LineSegment(Integer.parseInt(start[0]), Integer.parseInt(start[1]),
                    Integer.parseInt(end[0]), Integer.parseInt(end[1])));
        }

        tileCollisionJoints.put(Integer.valueOf(tileNo), tmp);
    }

    ArrayList<LineSegment> collisionLineSegments = new ArrayList<LineSegment>();

    for (int y = 0; y < getMap().height; y++) {
        for (int x = 0; x < getMap().width; x++) {
            int tileType = getMap().layers.get(1).tiles[(getMap().height - 1) - y][x];

            for (int n = 0; n < tileCollisionJoints.get(Integer.valueOf(tileType)).size(); n++) {
                LineSegment lineSeg = tileCollisionJoints.get(Integer.valueOf(tileType)).get(n);

                addOrExtendCollisionLineSegment(x * Assets.tileWidth + lineSeg.start().x,
                        y * Assets.tileHeight - lineSeg.start().y + Assets.tileHeight,
                        x * Assets.tileWidth + lineSeg.end().x,
                        y * Assets.tileHeight - lineSeg.end().y + Assets.tileHeight, collisionLineSegments);
            }
        }
    }

    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyDef.BodyType.StaticBody;
    groundBody = world.createBody(groundBodyDef);
    for (LineSegment lineSegment : collisionLineSegments) {
        PolygonShape environmentShape = new PolygonShape();
        environmentShape.setAsEdge(lineSegment.start().mul(1 / Assets.PIXELS_PER_METER_X),
                lineSegment.end().mul(1 / Assets.PIXELS_PER_METER_X));
        groundBody.createFixture(environmentShape, 0);
        environmentShape.dispose();
    }

    /**
     * Drawing a boundary around the entire map. We can't use a box because
     * then the world objects would be inside and the physics engine would
     * try to push them out.
     */

    PolygonShape mapBounds = new PolygonShape();
    mapBounds.setAsEdge(new Vector2(0.0f, 0.0f), new Vector2(getWidth() / Assets.PIXELS_PER_METER_X, 0.0f));
    groundBody.createFixture(mapBounds, 0);

    mapBounds.setAsEdge(new Vector2(0.0f, getHeight() / Assets.PIXELS_PER_METER_Y),
            new Vector2(getWidth() / Assets.PIXELS_PER_METER_X, getHeight() / Assets.PIXELS_PER_METER_Y));
    groundBody.createFixture(mapBounds, 0);

    mapBounds.setAsEdge(new Vector2(0.0f, 0.0f), new Vector2(0.0f, getHeight() / Assets.PIXELS_PER_METER_Y));
    groundBody.createFixture(mapBounds, 0);

    mapBounds.setAsEdge(new Vector2(getWidth() / Assets.PIXELS_PER_METER_X, 0.0f),
            new Vector2(getWidth() / Assets.PIXELS_PER_METER_X, getHeight() / Assets.PIXELS_PER_METER_Y));
    groundBody.createFixture(mapBounds, 0);

    mapBounds.dispose();
}

From source file:com.arkanoid.Actors.BoardActor.java

License:Open Source License

/**
 * Create a new level/*from w ww. j a v  a2 s .  c o m*/
 *
 * @param world
 * @param textures
 */
public BoardActor(World world, HashMap<BoardTextures, TextureRegion> textures, Array<TextureRegion> grounds) {
    this.world = world;
    this.textures = textures;
    this.grounds = grounds;

    // left border
    BodyDef def = new BodyDef();
    def.position.set(OFFSET_X - TILE_SIZE / 2f, OFFSET_Y + BOARD_HEIGHT / 2f);
    def.type = BodyDef.BodyType.StaticBody;
    body = world.createBody(def);
    PolygonShape box = new PolygonShape();
    box.setAsBox(TILE_SIZE / 2, BOARD_HEIGHT / 2);
    fixture = body.createFixture(box, 1);
    fixture.setUserData("board_left");
    fixture.setDensity(0f);
    fixture.setRestitution(0f);
    fixture.setFriction(0f);
    box.dispose();

    // right border
    def = new BodyDef();
    def.position.set(OFFSET_X + BOARD_WIDTH + TILE_SIZE / 2f, OFFSET_Y + BOARD_HEIGHT / 2f);
    def.type = BodyDef.BodyType.StaticBody;
    body = world.createBody(def);
    box = new PolygonShape();
    box.setAsBox(TILE_SIZE / 2, BOARD_HEIGHT / 2);
    fixture = body.createFixture(box, 1);
    fixture.setUserData("board_right");
    fixture.setDensity(0f);
    fixture.setRestitution(0f);
    fixture.setFriction(0f);
    box.dispose();

    // top border
    def = new BodyDef();
    def.position.set(OFFSET_X + BOARD_WIDTH / 2f, OFFSET_Y + BOARD_HEIGHT + TILE_SIZE / 2f);
    def.type = BodyDef.BodyType.StaticBody;
    body = world.createBody(def);
    box = new PolygonShape();
    box.setAsBox(BOARD_WIDTH / 2, TILE_SIZE / 2);
    fixture = body.createFixture(box, 1);
    fixture.setUserData("board_top");
    fixture.setDensity(0f);
    fixture.setRestitution(0f);
    fixture.setFriction(0f);
    box.dispose();
    //        def.position.set(OFFSET_X + width / 2f - border / 2f, OFFSET_Y + height / 2f + border / 2f);

    // Graph size
    setSize(BOARD_WIDTH * PPM, BOARD_HEIGHT * PPM);
    // Graph position
    setPosition(body.getPosition().x * PPM - getWidth() / 2f, body.getPosition().y * PPM - getHeight() / 2f);
}

From source file:com.badlogic.gdx.tests.box2d.ApplyForce.java

License:Apache License

@Override
protected void createWorld(World world) {
    world.setGravity(new Vector2(0, 0));

    float k_restitution = 0.4f;
    Body ground;//from   ww w.j a  v  a  2 s  .  c  o m

    {
        BodyDef bd = new BodyDef();
        bd.position.set(0, 20);
        ground = world.createBody(bd);

        EdgeShape shape = new EdgeShape();

        FixtureDef sd = new FixtureDef();
        sd.shape = shape;
        sd.density = 0;
        sd.restitution = k_restitution;

        shape.set(new Vector2(-20, -20), new Vector2(-20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(20, -20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, 20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, -20), new Vector2(20, -20));
        ground.createFixture(sd);

        shape.dispose();
    }

    {
        Transform xf1 = new Transform(new Vector2(), 0.3524f * (float) Math.PI);
        xf1.setPosition(xf1.mul(new Vector2(1, 0)));

        Vector2[] vertices = new Vector2[3];
        vertices[0] = xf1.mul(new Vector2(-1, 0));
        vertices[1] = xf1.mul(new Vector2(1, 0));
        vertices[2] = xf1.mul(new Vector2(0, 0.5f));

        PolygonShape poly1 = new PolygonShape();
        poly1.set(vertices);

        FixtureDef sd1 = new FixtureDef();
        sd1.shape = poly1;
        sd1.density = 4.0f;

        Transform xf2 = new Transform(new Vector2(), -0.3524f * (float) Math.PI);
        xf2.setPosition(xf2.mul(new Vector2(-1, 0)));

        vertices[0] = xf2.mul(new Vector2(-1, 0));
        vertices[1] = xf2.mul(new Vector2(1, 0));
        vertices[2] = xf2.mul(new Vector2(0, 0.5f));

        PolygonShape poly2 = new PolygonShape();
        poly2.set(vertices);

        FixtureDef sd2 = new FixtureDef();
        sd2.shape = poly2;
        sd2.density = 2.0f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.angularDamping = 5.0f;
        bd.linearDamping = 0.1f;

        bd.position.set(0, 2);
        bd.angle = (float) Math.PI;
        bd.allowSleep = false;
        m_body = world.createBody(bd);
        m_body.createFixture(sd1);
        m_body.createFixture(sd2);
        poly1.dispose();
        poly2.dispose();
    }

    {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 0.5f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 1.0f;
        fd.friction = 0.3f;

        for (int i = 0; i < 10; i++) {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.DynamicBody;

            bd.position.set(0, 5 + 1.54f * i);
            Body body = world.createBody(bd);

            body.createFixture(fd);

            float gravity = 10.0f;
            float I = body.getInertia();
            float mass = body.getMass();

            float radius = (float) Math.sqrt(2 * I / mass);

            FrictionJointDef jd = new FrictionJointDef();
            jd.localAnchorA.set(0, 0);
            jd.localAnchorB.set(0, 0);
            jd.bodyA = ground;
            jd.bodyB = body;
            jd.collideConnected = true;
            jd.maxForce = mass * gravity;
            jd.maxTorque = mass * radius * gravity;

            world.createJoint(jd);
        }

        shape.dispose();
    }
}

From source file:com.badlogic.gdx.tests.box2d.BodyTypes.java

License:Apache License

@Override
protected void createWorld(World world) {
    Body ground;//from ww  w .j av  a  2s. com

    {
        BodyDef bd = new BodyDef();
        ground = world.createBody(bd);

        EdgeShape shape = new EdgeShape();
        shape.set(new Vector2(-20, 0), new Vector2(20, 0));

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        ground.createFixture(fd);
        shape.dispose();
    }

    {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.position.set(0, 3.0f);
        m_attachment = world.createBody(bd);

        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 2.0f);
        m_attachment.createFixture(shape, 2.0f);
        shape.dispose();
    }

    {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.position.set(-4.0f, 5.0f);
        m_platform = world.createBody(bd);

        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 4.0f, new Vector2(4.0f, 0), 0.5f * (float) Math.PI);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.friction = 0.6f;
        fd.density = 2.0f;

        m_platform.createFixture(fd);
        shape.dispose();

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(m_attachment, m_platform, new Vector2(0, 5.0f));
        rjd.maxMotorTorque = 50.0f;
        rjd.enableMotor = true;
        world.createJoint(rjd);

        PrismaticJointDef pjd = new PrismaticJointDef();
        pjd.initialize(ground, m_platform, new Vector2(0, 5.0f), new Vector2(1, 0));

        pjd.maxMotorForce = 1000.0f;
        pjd.enableMotor = true;
        pjd.lowerTranslation = -10f;
        pjd.upperTranslation = 10.0f;
        pjd.enableLimit = true;

        world.createJoint(pjd);

        m_speed = 3.0f;
    }

    {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.position.set(0, 8.0f);
        Body body = world.createBody(bd);

        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.75f, 0.75f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.friction = 0.6f;
        fd.density = 2.0f;

        body.createFixture(fd);
        shape.dispose();
    }
}

From source file:com.badlogic.gdx.tests.box2d.Bridge.java

License:Apache License

@Override
protected void createWorld(World world) {
    Body ground;/* w  w w  .j av  a  2 s .co  m*/
    {
        BodyDef bd = new BodyDef();
        ground = world.createBody(bd);

        EdgeShape shape = new EdgeShape();
        shape.set(new Vector2(-40, 0), new Vector2(40.0f, 0));

        ground.createFixture(shape, 0);
        shape.dispose();
    }

    {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 0.125f);
        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 20.0f;
        fd.friction = 0.2f;

        RevoluteJointDef jd = new RevoluteJointDef();

        Body prevBody = ground;

        for (int i = 0; i < e_count; i++) {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.DynamicBody;
            bd.position.set(-14.5f + 1.0f * i, 5.0f);
            Body body = world.createBody(bd);
            body.createFixture(fd);

            Vector2 anchor = new Vector2(-15.0f + 1.0f * i, 5.0f);
            jd.initialize(prevBody, body, anchor);
            world.createJoint(jd);
            prevBody = body;
        }

        Vector2 anchor = new Vector2(-15.0f + 1.0f * e_count, 5.0f);
        jd.initialize(prevBody, ground, anchor);
        world.createJoint(jd);
        shape.dispose();
    }

    for (int i = 0; i < 2; i++) {
        Vector2[] vertices = new Vector2[3];
        vertices[0] = new Vector2(-0.5f, 0);
        vertices[1] = new Vector2(0.5f, 0);
        vertices[2] = new Vector2(0, 1.5f);

        PolygonShape shape = new PolygonShape();
        shape.set(vertices);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 1.0f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.position.set(-8.0f + 8.0f * i, 12.0f);
        Body body = world.createBody(bd);
        body.createFixture(fd);

        shape.dispose();
    }

    for (int i = 0; i < 3; i++) {
        CircleShape shape = new CircleShape();
        shape.setRadius(0.5f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 1.0f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.position.set(-6.0f + 6.0f * i, 10.0f);

        Body body = world.createBody(bd);
        body.createFixture(fd);

        shape.dispose();
    }
}