Exemplo n.º 1
0
  public void setUp() {

    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(x + width / 2, y + height / 2);
    bodyDef.type = BodyDef.BodyType.KinematicBody;

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;

    body = world.createBody(bodyDef);
    body.createFixture(fixtureDef);
    body.setUserData(Constants.robotNinjaID);

    body.setLinearVelocity(Constants.standardVelocity);

    sprite = new Sprite(texture);
    sprite.setSize(width, height);
    sprite.setOrigin(width / 2, height / 2);
    sprite.flip(false, flipy);
    sprite.setPosition(x, y);

    dead = false;
  }
Exemplo n.º 2
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;
  }
  private Entity buildPuffin(World world) {
    Entity e = engine.createEntity();
    e.add(new PuffinComponent());

    AnimationComponent a = new AnimationComponent();
    a.animations.put(
        "DEFAULT", new Animation(1f / 16f, Assets.getPuffinArray(), Animation.PlayMode.LOOP));
    a.animations.put(
        "RUNNING", new Animation(1f / 16f, Assets.getPuffinRunArray(), Animation.PlayMode.LOOP));
    e.add(a);
    StateComponent state = new StateComponent();
    state.set("DEFAULT");
    e.add(state);
    TextureComponent tc = new TextureComponent();
    e.add(tc);

    TransformComponent tfc = new TransformComponent();
    tfc.position.set(10f, 10f, 1f);
    tfc.rotation = 15f;
    tfc.scale.set(0.25f, 0.25f);
    e.add(tfc);

    BodyComponent bc = new BodyComponent();
    BodyDef bodyDef = new BodyDef();
    // We set our body to dynamic, for something like ground which doesn't move we would set it to
    // StaticBody
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    // Set our body's starting position in the world
    bodyDef.position.set(10f, 23f);

    // Create our body in the world using our body definition
    bc.body = world.createBody(bodyDef);
    bc.body.applyAngularImpulse(50f, true);

    // Create a circle shape and set its radius to 6
    CircleShape circle = new CircleShape();
    circle.setRadius(2f);

    // Create a fixture definition to apply our shape to
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = 20f;
    fixtureDef.friction = 0.4f;
    fixtureDef.restitution = 0.6f; // Make it bounce a little bit

    // Create our fixture and attach it to the body
    bc.body.createFixture(fixtureDef);

    // Remember to dispose of any shapes after you're done with them!
    // BodyDef and FixtureDef don't need disposing, but shapes do.
    circle.dispose();

    e.add(bc);
    return e;
  }
Exemplo n.º 4
0
  private void createGeometryAtPos(Vector2 pos) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(pos);

    Body body = world.createBody(bodyDef);
    if (spawnBoxes) {
      createBoxAtPos(body);
    } else {
      createCircleAtPos(body);
    }
  }
Exemplo n.º 5
0
  @Override
  public void create() { // creates everything you need LOL
    batch = new SpriteBatch();
    img = new Texture("Alien.png");
    sprite = new Sprite(img);

    // sets the sprite in the middle of the screen
    sprite.setPosition(
        Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2);

    // This is were the magic happens, this is the "physics world" created where the gravity is set
    // to 98
    // The 'f' makes 98 a float, the true means that it is active, vector 2d just means it takes x y
    // coor
    world = new World(new Vector2(0, -98f), true);

    // The body is the "object" set in the world, BodyDef makes the world aware of the object
    // basically so world Senpai notices
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    // using 1 to 1 dimensions, meaning 1 in physics engine is 1px
    // set the body to the same position as the sprite
    bodyDef.position.set(sprite.getX(), sprite.getY());

    // now create the body in the world!
    body = world.createBody(bodyDef);

    // now make the "shape" of the body that you just created
    shape = new PolygonShape();

    // in this example I made a box (you can make circles too and stuff) that surrounds the sprite
    // aka the hit-box
    // so make the shape the same dimensions as the sprite image we are using
    shape.setAsBox(sprite.getWidth() / 2, sprite.getHeight() / 2);

    // FixtureDef is used to add physical properties to the shape
    // Ex. density, mass, area etc.
    fixtureDef = new FixtureDef();

    // now assign the FixtureDef to the new shape that we just made
    fixtureDef.shape = shape;

    // Adding density using FixtureDef & adding it to the body so again world senpai notices
    fixtureDef.density = 1f;
    fixture = body.createFixture(fixtureDef);

    // the shape can be disposed to reduce clutter that will slow down the game
    shape.dispose();
  }
Exemplo n.º 6
0
  public static Body createMovingPlatform(
      World world, float x, float y, float width, float height, float restituition) {

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.KinematicBody;
    bodyDef.position.set(new Vector2(x, y));
    Body body = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);
    Fixture fixture = body.createFixture(shape, Constants.GROUND_DENSITY);
    fixture.setRestitution(restituition);
    body.setUserData(new GroundUserData());
    shape.dispose();
    return body;
  }
Exemplo n.º 7
0
  private void addBody(World world, float x, float y, boolean dirt) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    final Body body = world.createBody(bodyDef);
    body.setTransform(x + 0.5f, y + 0.5f, 0);

    final CircleShape shape = new CircleShape();
    shape.setRadius(0.1f);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    final Fixture fixture = body.createFixture(fixtureDef);
    shape.dispose();
    if (dirt) {
      dirts.add(fixture);
    }
  }
Exemplo n.º 8
0
  private Body addFinish(World world, Vector2 position) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    final Body body = world.createBody(bodyDef);
    body.setTransform(position.x + offset.x, position.y + offset.y, 0);

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.1f, 0.1f);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.isSensor = true;
    final Fixture fixture = body.createFixture(fixtureDef);
    fixture.setUserData("finish");
    shape.dispose();
    return body;
  }
Exemplo n.º 9
0
  private void createGoal(float x, float y) {
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    // create gravBot
    bdef.position.set(x / PPM, y / PPM);
    bdef.type = BodyType.StaticBody;
    Body body = gameWorldPhysics.createBody(bdef);

    shape.setAsBox(16 / PPM, 16 / PPM);
    fdef.shape = shape;
    body.createFixture(fdef);

    body.setUserData("Goal");

    goal = new Goal(body);
  }
Exemplo n.º 10
0
  public StandardEnemy(World world, float x, float y) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(2f, 4f);
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.fixedRotation = true;
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.friction = 0.3f;
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(WIDTH / 2, HEIGHT / 2);
    fixtureDef.shape = shape;
    fixtureDef.density = 3.0f;

    body = world.createBody(bodyDef);
    body.createFixture(fixtureDef).setUserData("dfs");
    // body.setUserData(this);

    shape.dispose();
  }
Exemplo n.º 11
0
  private void createGravBot() {
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    // create gravBot
    bdef.position.set(0 / PPM, 0 / PPM);
    bdef.type = BodyType.DynamicBody;
    Body body = gameWorldPhysics.createBody(bdef);

    shape.setAsBox(16 / PPM, 16 / PPM);
    fdef.shape = shape;
    body.createFixture(fdef);

    body.setUserData("Gravbot");

    // create GravBot
    gravBot = new GravBot(body);
  }
Exemplo n.º 12
0
  @Override
  Body initPhysicsBody(World world, float x, float y, float width, float height, float angle) {
    FixtureDef fixtureDef = new FixtureDef();
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position = new Vec2(0, 0);
    Body body = world.createBody(bodyDef);

    CircleShape circleShape = new CircleShape();
    circleShape.m_radius = RADIUS;
    fixtureDef.shape = circleShape;
    fixtureDef.density = 0.4f;
    fixtureDef.friction = 1f;
    fixtureDef.restitution = 0.0f;
    circleShape.m_p.set(0, 0);
    body.createFixture(fixtureDef);
    //        body.setLinearDamping(0.2f);
    body.setTransform(new Vec2(x, y), angle);
    return body;
  }
Exemplo n.º 13
0
  public void initWorld() {
    Vec2 gravity = new Vec2(0.0f, 9.8f);
    world = new World(gravity);

    // ground
    FixtureDef groundFixtureDef = new FixtureDef();
    PolygonShape groundShape = new PolygonShape();
    groundShape.setAsBox(20f, 0.1f);
    groundFixtureDef.shape = groundShape;
    groundFixtureDef.density = 25.0f;
    groundFixtureDef.filter = new Filter();
    groundFixtureDef.filter.categoryBits = 0x0001;

    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.position = new Vec2(0.0f, 3f);
    groundBodyDef.angle = 0.0f;
    groundBodyDef.type = BodyType.STATIC;

    groundBody = world.createBody(groundBodyDef);
    groundFixture = groundBody.createFixture(groundFixtureDef);
  }
Exemplo n.º 14
0
  public static Body createRunner(World world, float x, float y, float width, float height) {

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(new Vector2(x, y));
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.5f, 0.5f, new Vector2(2, 2), 45);
    Body body = world.createBody(bodyDef);

    body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE);
    Fixture fixture = body.createFixture(shape, Constants.RUNNER_DENSITY);
    body.setFixedRotation(true);
    fixture.setFriction(2f);

    body.resetMassData();
    body.setUserData(new RunnerUserData());
    shape.dispose();

    body.setBullet(true);

    return body;
  }
Exemplo n.º 15
0
  public Body createBody(int x, int y, int width, int height, boolean isStatic) {
    Body pBody;

    BodyDef def = new BodyDef();
    if (isStatic) {
      def.type = BodyDef.BodyType.StaticBody;
    } else {
      def.type = BodyDef.BodyType.DynamicBody;
    }

    def.position.set(x / PPM, y / PPM);
    def.fixedRotation = true;
    pBody = world.createBody(def);

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2 / PPM, height / 2 / PPM);

    pBody.createFixture(shape, 1.0f);
    shape.dispose();

    return pBody;
  }
Exemplo n.º 16
0
  private void definePlayer() {
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(32 / Gyaya.PPM, 32 / Gyaya.PPM);
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bodyDef);

    FixtureDef fixtureDef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(8f / Gyaya.PPM);
    fixtureDef.filter.categoryBits = Gyaya.PLAYER_BIT;
    fixtureDef.filter.maskBits =
        Gyaya.GROUND_BIT
            | Gyaya.BRICK_BIT
            | Gyaya.COIN_BIT
            | Gyaya.OBJECT_BIT
            | Gyaya.ENEMY_BIT
            | Gyaya.ENEMY_HEAD_BIT;

    fixtureDef.shape = shape;

    b2body.createFixture(fixtureDef);
    shape.setPosition(new Vector2(0, 4 / Gyaya.PPM));
    shape.setRadius(6f / Gyaya.PPM);
    b2body.createFixture(fixtureDef);

    EdgeShape head = new EdgeShape();
    head.set(
        new Vector2(-3 / Gyaya.PPM, 10f / Gyaya.PPM), new Vector2(3 / Gyaya.PPM, 10f / Gyaya.PPM));
    fixtureDef.shape = head;
    fixtureDef.isSensor = true;
    b2body.createFixture(fixtureDef).setUserData("head");

    EdgeShape feet = new EdgeShape();
    feet.set(
        new Vector2(-6 / Gyaya.PPM, -9f / Gyaya.PPM), new Vector2(6 / Gyaya.PPM, -9f / Gyaya.PPM));
    fixtureDef.shape = feet;
    fixtureDef.isSensor = true;
    b2body.createFixture(fixtureDef).setUserData("feet");
  }
Exemplo n.º 17
0
  public TileObject(PlayScreen screen, Rectangle bounds) {

    this.world = screen.getWorld();
    this.map = screen.getMap();
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(
        (bounds.getX() + bounds.getWidth() / 2) / StarWars.PPM,
        (bounds.getY() + bounds.getHeight() / 2) / StarWars.PPM);

    body = world.createBody(bdef);

    shape.setAsBox(bounds.getWidth() / 2 / StarWars.PPM, bounds.getHeight() / 2 / StarWars.PPM);
    fdef.shape = shape;
    fdef.filter.categoryBits = StarWars.PLATFORM_BIT;
    fixture = body.createFixture(fdef);
  }
Exemplo n.º 18
0
  public PatrolShip() {
    // Creating a box2D entity
    BodyDef circleDef = new BodyDef();
    circleDef.type = BodyDef.BodyType.DynamicBody;

    body = com.astrodestroyer.Game.b2World.createBody(circleDef);

    shape = new CircleShape();
    shape.setRadius(radius);

    fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.0f;
    fixtureDef.restitution = 0.0f;
    fixtureDef.filter.groupIndex = 1;
    fixture = body.createFixture(fixtureDef);

    Random rnd = new Random();
    body.setTransform(
        (rnd.nextFloat() - 0.5f) * 2f, (rnd.nextFloat() - 0.5f) * 2f, rnd.nextFloat() * 2f - 1f);
    body.setLinearVelocity(rnd.nextFloat() * 0.5f - 0.25f, rnd.nextFloat() * 0.5f - 0.25f);
  }
  private Entity buildFloorEntity(World world) {

    Entity e = engine.createEntity();
    Vector2 screenMeters = RenderingSystem.getScreenSizeInMeters();
    Gdx.app.log("Splash Screen", "Screen Meters:" + screenMeters.x + " x " + screenMeters.y);
    Vector2 screenPixels = RenderingSystem.getScreenSizeInPixesl();
    Gdx.app.log("Splash Screen", "Screen Pixels:" + screenPixels.x + " x " + screenPixels.y);
    // Create our body definition
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyDef.BodyType.StaticBody;

    // Set its world position
    groundBodyDef.position.set(new Vector2(6f, 1f));
    groundBodyDef.angle = 45f;

    BodyComponent bc = new BodyComponent();
    // Create a body from the defintion and add it to the world
    bc.body = world.createBody(groundBodyDef);

    // Create a polygon shape
    PolygonShape groundBox = new PolygonShape();
    // Set the polygon shape as a box which is twice the size of our view port and 20 high
    // (setAsBox takes half-width and half-height as arguments)

    groundBox.setAsBox(5f, 1f);

    // Create a fixture from our polygon shape and add it to our ground body
    bc.body.createFixture(groundBox, 0.0f);

    // Clean up after ourselves
    groundBox.dispose();

    e.add(bc);

    return e;
  }
Exemplo n.º 20
0
 private Body createBody(float x, float y, float width, float height, boolean sensor) {
   BodyDef bodyDef = new BodyDef();
   bodyDef.type = BodyDef.BodyType.KinematicBody;
   bodyDef.position.set(new Vector2(x, y));
   bodyDef.allowSleep = true;
   PolygonShape shape = new PolygonShape();
   shape.setAsBox(width / 2, height / 2, new Vector2(0, 0), 0);
   Body _body = WorldUtils.world.createBody(bodyDef);
   Fixture fixture = _body.createFixture(shape, 1.0f);
   fixture.setFriction(0);
   fixture.setSensor(sensor);
   if (!sensor) {
     fixture.setUserData(Constants.POTION_FIXTURE);
   } else {
     fixture.setUserData(Constants.NOT_COLLIDER_FIXTURE);
   }
   Filter filter = new Filter();
   filter.categoryBits = Constants.COLLISION_CREATURE;
   filter.maskBits =
       Constants.COLLISION_GROUND + Constants.COLLISION_CREATURE + Constants.COLLISION_FIELD;
   fixture.setFilterData(filter);
   _body.setUserData(this);
   return _body;
 }
Exemplo n.º 21
0
  /**
   * Create a new paddle.
   *
   * @param world The world the paddle will be added to.
   * @param y The height of the paddle (starts centered on the x)
   * @param mode The keys that will move this paddle
   */
  public Paddle(World world, int y, MovementMode mode) {
    Mode = mode;

    // Respond to the keyboard
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(this);

    // Add the physics body
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(world.Bounds.width / 2, y);
    bd.linearDamping = 0.0f;
    bd.angularDamping = 0.01f;

    FixtureDef fd = new FixtureDef();
    fd.shape = new PolygonShape();
    ((PolygonShape) fd.shape).setAsBox(SIZE.width / 2, SIZE.height / 2);
    fd.density = 0.1f;
    fd.friction = 0.0f;
    fd.restitution = 1.0f;

    j2dBody = world.j2dWorld.createBody(bd);
    j2dBody.createFixture(fd);
    j2dBody.setUserData(this);

    // Limit it to only x movement
    BodyDef gbd = new BodyDef();
    gbd.type = BodyType.STATIC;
    bd.position.set(world.Bounds.width / 2, y);

    PrismaticJointDef pjd = new PrismaticJointDef();
    pjd.collideConnected = true;
    pjd.initialize(
        j2dBody, world.j2dWorld.createBody(gbd), j2dBody.getWorldCenter(), new Vec2(1.0f, 0.0f));
    world.j2dWorld.createJoint(pjd);
  }
Exemplo n.º 22
0
  @Override
  public void create() {
    cam = new OrthographicCamera(48, 32);
    cam.position.set(0, 15, 0);
    cam.update();

    Box2D.init();
    world = new World(new Vector2(0, -9.8f), true);
    dDebugRenderer = new Box2DDebugRenderer();

    spawnBoxes = false;
    // GROUND
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(0, 0);

    ground = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(15, 1);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 0f;

    ground.createFixture(fixtureDef);

    // CIRCLE
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 10);

    circle = world.createBody(bodyDef);

    CircleShape circleShape = new CircleShape();
    circleShape.setRadius(1);

    fixtureDef.shape = circleShape;
    fixtureDef.density = 10;
    fixtureDef.restitution = 1;

    circle.createFixture(fixtureDef);

    // BOX
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 15);

    box = world.createBody(bodyDef);

    bodyDef.bullet = false;
    shape.setAsBox(1, 1);

    fixtureDef.friction = 100f;
    fixtureDef.restitution = 0.5f;
    fixtureDef.shape = shape;
    fixtureDef.density = 2;

    box.createFixture(fixtureDef);

    // PLATFORM
    bodyDef.type = BodyDef.BodyType.KinematicBody;
    bodyDef.position.set(-10, 6);

    platform = world.createBody(bodyDef);

    shape.setAsBox(3, .5f);

    fixtureDef.shape = shape;
    fixtureDef.density = 0;
    fixtureDef.friction = 7;
    fixtureDef.restitution = 0;

    platform.createFixture(fixtureDef);

    Gdx.input.setInputProcessor(new MyInputProcessor());

    platform.setLinearVelocity(PLATFORM_VELOCITY, 0);
  }
Exemplo n.º 23
0
  @Override
  public void create() {
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");

    // Create two identical sprites slightly offset from each other vertically
    sprite = new Sprite(img);
    sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2 + 200);
    sprite2 = new Sprite(img);
    sprite2.setPosition(-sprite.getWidth() / 2 + 20, -sprite.getHeight() / 2 + 400);

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

    // Sprite1's Physics body
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(
        (sprite.getX() + sprite.getWidth() / 2) / PIXELS_TO_METERS,
        (sprite.getY() + sprite.getHeight() / 2) / PIXELS_TO_METERS);

    body = world.createBody(bodyDef);

    // Sprite2's physics body
    BodyDef bodyDef2 = new BodyDef();
    bodyDef2.type = BodyDef.BodyType.DynamicBody;
    bodyDef2.position.set(
        (sprite2.getX() + sprite2.getWidth() / 2) / PIXELS_TO_METERS,
        (sprite2.getY() + sprite2.getHeight() / 2) / PIXELS_TO_METERS);

    body2 = world.createBody(bodyDef2);

    // Both bodies have identical shape
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(
        sprite.getWidth() / 2 / PIXELS_TO_METERS, sprite.getHeight() / 2 / PIXELS_TO_METERS);

    // Sprite1
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 0.1f;
    fixtureDef.restitution = 0.5f;

    // Sprite2
    FixtureDef fixtureDef2 = new FixtureDef();
    fixtureDef2.shape = shape;
    fixtureDef2.density = 0.1f;
    fixtureDef2.restitution = 0.5f;

    body.createFixture(fixtureDef);
    body2.createFixture(fixtureDef2);

    shape.dispose();

    // Now the physics body of the bottom edge of the screen
    BodyDef bodyDef3 = new BodyDef();
    bodyDef3.type = BodyDef.BodyType.StaticBody;
    float w = Gdx.graphics.getWidth() / PIXELS_TO_METERS;
    float h = Gdx.graphics.getHeight() / PIXELS_TO_METERS;

    bodyDef3.position.set(0, 0);
    FixtureDef fixtureDef3 = new FixtureDef();

    EdgeShape edgeShape = new EdgeShape();
    edgeShape.set(-w / 2, -h / 2, w / 2, -h / 2);
    fixtureDef3.shape = edgeShape;

    bodyEdgeScreen = world.createBody(bodyDef3);
    bodyEdgeScreen.createFixture(fixtureDef3);
    edgeShape.dispose();

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    /*world.setContactListener(new ContactListener() {
        @Override
        public void beginContact(Contact contact) {
            // Check to see if the collision is between the second sprite and the bottom of the screen
            // If so apply a random amount of upward force to both objects... just because
            if((contact.getFixtureA().getBody() == bodyEdgeScreen &&
                    contact.getFixtureB().getBody() == body2)
                    ||
                    (contact.getFixtureA().getBody() == body2 &&
                            contact.getFixtureB().getBody() == bodyEdgeScreen)) {

                body.applyForceToCenter(0,MathUtils.random(20,50),true);
                body2.applyForceToCenter(0, MathUtils.random(20,50), true);
            }
        }

        @Override
        public void endContact(Contact contact) {
        }

        @Override
        public void preSolve(Contact contact, Manifold oldManifold) {
        }

        @Override
        public void postSolve(Contact contact, ContactImpulse impulse) {
        }
    });*/
  }
  @Override
  public void resize(int width, int height) {
    PPuX = width / 10;
    System.out.println("width = " + width);
    System.out.println("height = " + height);
    PPuY = height / 10;
    world = new World(new Vector2(0, -9.8f), false);
    renderer = new Box2DDebugRenderer();
    camera = new OrthographicCamera(width, height);
    debugMatrix = new Matrix4(camera.combined);

    Circle.setBounds(
        Circle.getX() * PPuX,
        Circle.getY() * PPuY,
        Circle.getWidth() * PPuX,
        Circle.getHeight() * PPuY);
    Circle.setOrigin(Circle.getWidth() / 2, Circle.getHeight() / 2);
    BodyDef circleDef = new BodyDef();
    circleDef.type = BodyType.DynamicBody;
    // To allign the Circle sprite with box 2d
    circleDef.position.set(
        convertToBox(Circle.getX() + Circle.getWidth() / 2),
        convertToBox(Circle.getY() + Circle.getHeight() / 2));
    circleBody = world.createBody(circleDef);
    // box2d builds around 0,0 you can see -X and -Y, this makes sure that you only see X,Y
    debugMatrix.translate(-camera.viewportWidth / 2, -camera.viewportHeight / 2, 0);
    // scale the debug matrix by the scaling so everything looks normal
    debugMatrix.scale(BOX_TO_WORLD, BOX_TO_WORLD, 0);
    circleShape = new CircleShape();
    circleShape.setRadius(convertToBox(Circle.getWidth() / 2));

    FixtureDef circleFixture = new FixtureDef();
    circleFixture.shape = circleShape;
    circleFixture.density = 0.4f;
    circleFixture.friction = 0.2f;
    circleFixture.restitution = 1f;

    circleBody.createFixture(circleFixture);
    circleBody.setUserData(Circle);

    // create ground
    BodyDef groundDef = new BodyDef();
    groundDef.position.set(convertToBox(camera.viewportWidth / 2), 0);

    Body groundBody = world.createBody(groundDef);

    PolygonShape groundBox = new PolygonShape();

    groundBox.setAsBox(convertToBox(camera.viewportWidth / 2), 0);
    groundBody.createFixture(groundBox, 0);

    BodyDef def = new BodyDef();
    def.type = BodyType.DynamicBody;
    def.position.set(0, 0);
    Body box = world.createBody(def);

    PolygonShape poly = new PolygonShape();
    poly.setAsBox(0.1f, 0.2f);
    playerPhysicsFixture = box.createFixture(poly, 1);
    poly.dispose();

    CircleShape circle = new CircleShape();
    circle.setRadius(0.1f);
    circle.setPosition(new Vector2(0, -0.2f));
    playerSensorFixture = box.createFixture(circle, 0);
    circle.dispose();

    box.setBullet(true);

    player = box;
    player.setTransform(1.0f, 2.0f, 0);
    player.setFixedRotation(true);
  }