Package com.badlogic.gdx.physics.box2d

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


    boxBodyDef.position.x = pCenterX / pPixelToMeterRatio;
    boxBodyDef.position.y = pCenterY / pPixelToMeterRatio;

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final PolygonShape boxPoly = new PolygonShape();

    final float halfWidth = pWidth * 0.5f / pPixelToMeterRatio;
    final float halfHeight = pHeight * 0.5f / pPixelToMeterRatio;

    boxPoly.setAsBox(halfWidth, halfHeight);
    pFixtureDef.shape = boxPoly;

    boxBody.createFixture(pFixtureDef);

    boxPoly.dispose();

    boxBody.setTransform(boxBody.getWorldCenter(), MathUtils.degToRad(pRotation));

    return boxBody;
  }
View Full Code Here


    final BodyDef lineBodyDef = new BodyDef();
    lineBodyDef.type = BodyType.StaticBody;
   
    final Body boxBody = pPhysicsWorld.createBody(lineBodyDef);
   
    final PolygonShape linePoly = new PolygonShape();
   
    linePoly.setAsEdge(new Vector2(pX1 / pPixelToMeterRatio, pY1 / pPixelToMeterRatio), new Vector2(pX2 / pPixelToMeterRatio, pY2 / pPixelToMeterRatio));
    pFixtureDef.shape = linePoly;
   
    boxBody.createFixture(pFixtureDef);
   
    linePoly.dispose();
   
    return boxBody;
  }
View Full Code Here

    boxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] / pPixelToMeterRatio;
    boxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] / pPixelToMeterRatio;

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final PolygonShape boxPoly = new PolygonShape();

    boxPoly.set(pVertices);
    pFixtureDef.shape = boxPoly;

    boxBody.createFixture(pFixtureDef);

    boxPoly.dispose();

    return boxBody;
  }
View Full Code Here

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final int vertexCount = pTriangleVertices.size();
    for(int i = 0; i < vertexCount; /* */) {
      final PolygonShape boxPoly = new PolygonShape();

      TMP_TRIANGLE[2] = pTriangleVertices.get(i++);
      TMP_TRIANGLE[1] = pTriangleVertices.get(i++);
      TMP_TRIANGLE[0] = pTriangleVertices.get(i++);

      boxPoly.set(TMP_TRIANGLE);
      pFixtureDef.shape = boxPoly;

      boxBody.createFixture(pFixtureDef);

      boxPoly.dispose();
    }

    return boxBody;
  }
View Full Code Here

  public NetworkShip(String id, int place, World world, int x, int y, float angle) {
    this.id = id;
    this.place = place;
   
    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;
    boxBodyDef.linearDamping = 1.0f;
    Body boxBody = world.createBody(boxBodyDef);

    boxBody.createFixture(boxPoly, 1);
    // add the box to our list of boxes
    body = boxBody;
   
    body.setUserData(this);
   

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

    player = new Player(world,5,5,0);
  }
 
  private void createEnemies() {
    PolygonShape boxPoly = new PolygonShape();
    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;
      Body boxBody = world.createBody(boxBodyDef);

      boxBody.createFixture(boxPoly, 1);

      // add the box to our list of boxes
      enemies.add(boxBody);
    }

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

 
  public float sinkAngle = -1;
  public float sinkSpeed = MathUtils.random(-1,1);
 
  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;
    boxBodyDef.linearDamping = 1.0f;
    Body boxBody = world.createBody(boxBodyDef);

    boxBody.createFixture(boxPoly, 1);
    // add the box to our list of boxes
    body = boxBody;
   
    body.setUserData(this);
   
    // 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();
    }



    player = new Player(world,5,5,0);
View Full Code Here

    player = new Player(world,5,5,0);
  }
 
  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;
      Body boxBody = world.createBody(boxBodyDef);

      boxBody.createFixture(boxPoly, 1);

      enemies.add(new EnemyShip(boxBody));
      boxBody.setUserData(enemies.get(enemies.size-1));
    }

    boxPoly.dispose();
  }
View Full Code Here

    // region attachment, but this is just an example.
    for (Slot slot : skeleton.getSlots()) {
      if (!(slot.getAttachment() instanceof Box2dAttachment)) continue;
      Box2dAttachment attachment = (Box2dAttachment)slot.getAttachment();

      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

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.