Example usage for com.badlogic.gdx.physics.box2d Shape setRadius

List of usage examples for com.badlogic.gdx.physics.box2d Shape setRadius

Introduction

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

Prototype

public abstract void setRadius(float radius);

Source Link

Document

Sets the radius of this shape

Usage

From source file:com.hajnar.GravityShip.GameObjects.BlackHole.java

License:Apache License

public BlackHole(World world, float x, float y, int strength) {
    super(world, BodyType.StaticBody, OBJECT_TYPE_BLACKHOLE, x, y, 0);

    sprite = new Sprite(Assets.blackHoleRegions[0]);
    sprite.setPosition(objectBody.getPosition().x * Helper.BOX_TO_WORLD - sprite.getWidth() / 2,
            objectBody.getPosition().y * Helper.BOX_TO_WORLD - sprite.getHeight() / 2);

    timeWarp = new Animation(0.05f, Assets.blackHoleRegions);

    Shape circle = new CircleShape();
    circle.setRadius(0.55f);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;//from www .  j a v a  2 s  .c o m

    objectBody.createFixture(fixtureDef);

    circle.dispose();

    objectBody.setUserData(this);

    animTime = 0;
    this.strength = strength;
}

From source file:es.eucm.ead.engine.gameobjects.effects.PhysicsEffectGO.java

License:Open Source License

public static void createBody(World world, SceneElement e, ValueMap valueMap) {
    float x = valueMap.getValue(e, SceneElement.VAR_X, 0f) / WORLD_SCALE;
    float y = valueMap.getValue(e, SceneElement.VAR_Y, 0f) / WORLD_SCALE;
    float width = valueMap.getValue(e, SceneElement.VAR_WIDTH, 1) / WORLD_SCALE;
    float height = valueMap.getValue(e, SceneElement.VAR_HEIGHT, 1) / WORLD_SCALE;

    // TODO what if corner is not center?
    PhType phType = valueMap.getValue(e, PhysicsEf.VAR_PH_TYPE, PhType.DYNAMIC);
    PhShape phShape = valueMap.getValue(e, PhysicsEf.VAR_PH_SHAPE, PhShape.RECTANGULAR);

    Shape s = null;
    switch (phShape) {
    case CIRCULAR:
        s = new CircleShape();
        s.setRadius(width / 2);
        break;/*from   w  w  w  .  ja  v a2s.  co m*/
    default:
        s = new PolygonShape();
        ((PolygonShape) s).setAsBox(width / 2, height / 2);

    }

    BodyDef bd = new BodyDef();

    switch (phType) {
    case STATIC:
        bd.type = BodyType.StaticBody;
        break;
    case DYNAMIC:
        bd.type = BodyType.DynamicBody;
        break;
    }

    bd.position.set(x, y);
    bd.angle = valueMap.getValue(e, SceneElement.VAR_ROTATION, 0f);

    FixtureDef fixture = new FixtureDef();
    fixture.shape = s;
    fixture.density = valueMap.getValue(e, PhysicsEf.VAR_PH_DENSITY, 1f);
    fixture.friction = valueMap.getValue(e, PhysicsEf.VAR_PH_FRICTION, 1f);
    fixture.restitution = valueMap.getValue(e, PhysicsEf.VAR_PH_RESTITUTION, 1f);

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

    body.resetMassData();

    valueMap.setValue(e.getId(), VAR_PH_BODY, body);
}

From source file:loon.physics.PhysicsFixtureDefBuilder.java

License:Apache License

public PhysicsFixtureDefBuilder circleShape(float radius) {
    Shape shape = new CircleShape();
    shape.setRadius(radius);
    fixtureDef.shape = shape;/*from ww w . j av a2  s . c o  m*/
    return this;
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** creates a deep copy of a {@link Shape}<br/>
 *  <strong>Note: The {@link ChainShape#setPrevVertex(float, float) previous} and {@link ChainShape#setNextVertex(float, float) next} vertex of a {@link ChainShape} will not be copied since this is not possible due to the API.</strong>
 *  @param shape the {@link Shape} to copy
 *  @return a {@link Shape} exactly like the one passed in */
public static Shape copy(Shape shape) {
    Shape copy;
    switch (shape.getType()) {
    case Circle://from   w  ww  . ja v a 2s .  c o m
        CircleShape circleCopy = (CircleShape) (copy = new CircleShape());
        circleCopy.setPosition(((CircleShape) shape).getPosition());
        break;
    case Polygon:
        PolygonShape polyCopy = (PolygonShape) (copy = new PolygonShape()), poly = (PolygonShape) shape;
        float[] vertices = new float[poly.getVertexCount()];
        for (int i = 0; i < vertices.length; i++) {
            poly.getVertex(i, vec2_0);
            vertices[i++] = vec2_0.x;
            vertices[i] = vec2_0.y;
        }
        polyCopy.set(vertices);
        break;
    case Edge:
        EdgeShape edgeCopy = (EdgeShape) (copy = new EdgeShape()), edge = (EdgeShape) shape;
        edge.getVertex1(vec2_0);
        edge.getVertex2(vec2_1);
        edgeCopy.set(vec2_0, vec2_1);
        break;
    case Chain:
        ChainShape chainCopy = (ChainShape) (copy = new ChainShape()), chain = (ChainShape) shape;
        vertices = new float[chain.getVertexCount()];
        for (int i = 0; i < vertices.length; i++) {
            chain.getVertex(i, vec2_0);
            vertices[i++] = vec2_0.x;
            vertices[i] = vec2_0.y;
        }
        if (chain.isLooped())
            chainCopy.createLoop(GeometryUtils.toVector2Array(vertices));
        else
            chainCopy.createChain(vertices);
        break;
    default:
        return shape;
    }
    copy.setRadius(shape.getRadius());
    return copy;
}

From source file:Utils.CreateCircle.java

public static Body createCircle(World world, int x, int y, float radius) {
    Shape c = new CircleShape();
    c.setRadius(radius);
    BodyDef bd = new BodyDef();
    bd.type = BodyDef.BodyType.DynamicBody;

    Body b = world.createBody(bd);//  w ww .j  a va2  s.  c  o  m
    b.createFixture(c, 1f);
    b.setTransform(x, y, 0);
    return b;
}