Exemplo n.º 1
0
  private Body initPhysicsBody(World world, float x, float y) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position = new Vec2(0, 0);
    Body body = world.createBody(bodyDef);

    PolygonShape shape = new PolygonShape();
    Transform fx = new Transform();
    fx.position.set(100f, 100f);
    shape.centroid(fx);

    shape.setAsBox(
        sprite.layer().width() * GameScreen.M_PER_PIXEL / 2,
        sprite.layer().height() * GameScreen.M_PER_PIXEL / 2);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 0.4f;
    fixtureDef.friction = 0.1f;
    fixtureDef.restitution = 0f;
    body.createFixture(fixtureDef);
    body.setLinearDamping(0.2f);
    body.setTransform(new Vec2(x, y), 0f);

    //        MassData md = body.getMassData();
    //        massD.center.set(2f, 0); body.setMassData(massD);

    return body;
  }
Exemplo n.º 2
0
  public void update(int delta) {
    if (!hasLoaded) return;
    sprite.layer().setRotation(body.getAngle());
    //        float a= 0.6f;
    //        float i;
    //        for(i=0f;i<a;i=i+0.1f){
    //            body.setTransform(body.getPosition(),i);}

  }
Exemplo n.º 3
0
  public void paint(Clock clock) {
    if (!hasLoaded) return;

    // body.setLinearVelocity(new Vec2(30 * MathUtils.cos(GameScreen.angle), 30 *
    // MathUtils.sin(GameScreen.angle)));

    sprite
        .layer()
        .setTranslation(
            (body.getPosition().x / GameScreen.M_PER_PIXEL),
            (body.getPosition().y / GameScreen.M_PER_PIXEL));
    Vec2 delta = new Vec2(80f - body.getPosition().x, 400f - body.getPosition().y);
    float angle = MathUtils.atan2(delta.x, delta.y);
    body.setLinearVelocity(new Vec2(8 * -MathUtils.cos(angle), 8 * MathUtils.sin(angle)));
  }
Exemplo n.º 4
0
 public void closebody() {
   body.setActive(false);
   sprite.layer().destroy();
 }
Exemplo n.º 5
0
  public Layer layer() {

    return sprite.layer();
  }