Package com.badlogic.gdx.physics.box2d

Examples of com.badlogic.gdx.physics.box2d.PolygonShape


    world = new World(new Vector2(0, -10), true);

    float[] vertices = {-0.07421887f, -0.16276085f, -0.12109375f, -0.22786504f, -0.157552f, -0.7122401f, 0.04296875f,
      -0.7122401f, 0.110677004f, -0.6419276f, 0.13151026f, -0.49869835f, 0.08984375f, -0.3190109f};

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

    // next we create a static ground platform. This platform
    // is not moveable and will not react to any influences from
    // outside. It will however influence other bodies. First we
    // create a PolygonShape that holds the form of the platform.
    // it will be 100 meters wide and 2 meters high, centered
    // around the origin
    PolygonShape groundPoly = new PolygonShape();
    groundPoly.setAsBox(50, 1);

    // next we create the body for the ground platform. It's
    // simply a static body.
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyType.StaticBody;
    groundBody = world.createBody(groundBodyDef);

    // finally we add a fixture to the body using the polygon
    // defined above. Note that we have to dispose PolygonShapes
    // and CircleShapes once they are no longer used. This is the
    // only time you have to care explicitely for memomry managment.
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = groundPoly;
    fixtureDef.filter.groupIndex = 0;
    groundBody.createFixture(fixtureDef);
    groundPoly.dispose();

    PolygonShape boxPoly = new PolygonShape();
    boxPoly.setAsBox(1, 1);

    // Next we create the 50 box bodies using the PolygonShape we just
    // defined. This process is similar to the one we used for the ground
    // body. Note that we reuse the polygon for each body fixture.
    for (int i = 0; i < 20; i++) {
      // Create the BodyDef, set a random position above the
      // ground and create a new body
      BodyDef boxBodyDef = new BodyDef();
      boxBodyDef.type = BodyType.DynamicBody;
      boxBodyDef.position.x = -24 + (float)(Math.random() * 48);
      boxBodyDef.position.y = 10 + (float)(Math.random() * 100);
      Body boxBody = world.createBody(boxBodyDef);

      boxBody.createFixture(boxPoly, 1);
    }

    // we are done, all that's left is disposing the boxPoly
    boxPoly.dispose();
  }
View Full Code Here


    world = new World(new Vector2(0, 0), false);
   
//    debugRenderer = new Box2DDebugRenderer( true, true, true, true );
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(-50f  , -50f  );
        vertices[1] = new Vector2(-45f , -50f  );
        vertices[2] = new Vector2(-45f , 50f);
        vertices[3] = new Vector2(-50f , 50f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(45f  , -50f  );
        vertices[1] = new Vector2(50f , -50f  );
        vertices[2] = new Vector2(50f , 50f);
        vertices[3] = new Vector2(45f , 50f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(50f  , -40f  );
        vertices[1] = new Vector2(50f , -35f  );
        vertices[2] = new Vector2(-50f , -35f);
        vertices[3] = new Vector2(-50f , -40f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(50f  , 55f  );
        vertices[1] = new Vector2(50f , 60f  );
        vertices[2] = new Vector2(-50f , 60f);
        vertices[3] = new Vector2(-50f , 55f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(60f  , 0f  );
        vertices[1] = new Vector2(70f , 20f  );
        vertices[2] = new Vector2(0f , -55);
        vertices[3] = new Vector2(5f , -75f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(80f  , 0f  );
        vertices[1] = new Vector2(90f , 10f  );
        vertices[2] = new Vector2(0f , 85);
        vertices[3] = new Vector2(5f , 68f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(0f  , -60f  );
        vertices[1] = new Vector2(-50f , 0f  );
        vertices[2] = new Vector2(-60f , 0);
        vertices[3] = new Vector2(-10f , -60f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
    {
      PolygonShape groundPoly = new PolygonShape();
      Vector2[] vertices = new Vector2[4]
     
        vertices[0] = new Vector2(0f  , 75f  );
        vertices[1] = new Vector2(-65f , 30f  );
        vertices[2] = new Vector2(-50f , 30);
        vertices[3] = new Vector2(10f , 75f);
        groundPoly.set(vertices);
 
      BodyDef groundBodyDef = new BodyDef();
      groundBodyDef.type = BodyType.StaticBody;
      groundBodyDef.position.x = 10;
      groundBodyDef.position.y = 0;
      groundBody = world.createBody(groundBodyDef);
 
      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = groundPoly;
      fixtureDef.filter.groupIndex = 0;
      groundBody.createFixture(fixtureDef);
      groundPoly.dispose();
    }
   
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.physics.box2d.PolygonShape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.