Package com.badlogic.gdx.physics.box2d

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


 
  public Player(World world, int x, int y, float angle) {
    PolygonShape boxPoly = new PolygonShape();
    boxPoly.setAsBox(1.5f, 4f);
   
    BodyDef boxBodyDef = new BodyDef();
    boxBodyDef.type = BodyType.DynamicBody;
    boxBodyDef.position.x = x;
    boxBodyDef.position.y = y;
    boxBodyDef.angle = angle;
    boxBodyDef.angularDamping = 1f;
View Full Code Here


        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);
 
View Full Code Here

  private void createEnemies(int howMuch) {
    PolygonShape boxPoly = new PolygonShape();
    boxPoly.setAsBox(1.5f, 4f);

    for (int i = 0; i < howMuch; i++) {
      BodyDef boxBodyDef = new BodyDef();
      boxBodyDef.type = BodyType.DynamicBody;
      boxBodyDef.position.x = MathUtils.random(-25, 45);
      boxBodyDef.position.y = MathUtils.random(-20, 45);
      boxBodyDef.angularDamping = 1f;
      boxBodyDef.linearDamping = 1.0f;
View Full Code Here

   
    return true;
  }
 
  public Body createCircle(BodyType type, float radius, float density) {
    BodyDef def = new BodyDef();
    def.type = type;
    def.linearDamping = 5;
    Body box = world.createBody(def);

    CircleShape poly = new CircleShape();
View Full Code Here

    boxPoly.setAsBox(1.5f, 4f);

    for (int i = 0; i < 10; 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 = 2;
      boxBodyDef.position.y = 2;
      boxBodyDef.angularDamping = 1f;
      boxBodyDef.linearDamping = 1.0f;
View Full Code Here

   
    player.lastShot = 0;
  }
 
  public Body createCircle(BodyType type, float radius, float density) {
    BodyDef def = new BodyDef();
    def.type = type;
    Body box = world.createBody(def);

    CircleShape poly = new CircleShape();
    poly.setRadius(radius);
View Full Code Here

      PolygonShape boxPoly = new PolygonShape();
      boxPoly.setAsBox(attachment.getWidth() / 2 * attachment.getScaleX(),
        attachment.getHeight() / 2 * attachment.getScaleY(), vector.set(attachment.getX(), attachment.getY()),
        attachment.getRotation() * MathUtils.degRad);

      BodyDef boxBodyDef = new BodyDef();
      boxBodyDef.type = BodyType.StaticBody;
      attachment.body = world.createBody(boxBodyDef);
      attachment.body.createFixture(boxPoly, 1);

      boxPoly.dispose();
View Full Code Here

    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);

View Full Code Here

        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);
 
View Full Code Here

   
    return true;
  }
 
  public Body createCircle(BodyType type, float radius, float density) {
    BodyDef def = new BodyDef();
    def.type = type;
    def.linearDamping = 5;
    Body box = world.createBody(def);

    CircleShape poly = new CircleShape();
View Full Code Here

TOP

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

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.