@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);
  }
Ejemplo n.º 2
0
 /** Multiplies the current transformation matrix by a translation matrix. */
 public void translate(float x, float y, float z) {
   transform.translate(x, y, z);
   matrixDirty = true;
 }
Ejemplo n.º 3
0
  @Override
  public void draw() {
    if (_flickerTimer != 0) {
      _flicker = !_flicker;
      if (_flicker) return;
    }

    FlxCamera camera = FlxG._activeCamera;

    if (cameras == null) cameras = FlxG.cameras;

    if (!cameras.contains(camera, true)) return;

    if (!onScreen(camera)) return;

    _point.x = x - (camera.scroll.x * scrollFactor.x) - offset.x;
    _point.y = y - (camera.scroll.y * scrollFactor.y) - offset.y;
    _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f;
    _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f;

    // scaling
    BitmapFont font = _textField.getFont();
    if (scale.x != font.getScaleX() || scale.y != font.getScaleY()) {
      _textField.getFont().setScale(scale.x, scale.y);
      calcFrame();
    }

    // position
    _textField.setPosition(_point.x, _point.y);

    // rotation
    if (angle != 0) {
      _matrix = FlxG.batch.getTransformMatrix().cpy();

      Matrix4 rotationMatrix = FlxG.batch.getTransformMatrix();
      rotationMatrix.translate(
          _textField.getX() + (width / 2), _textField.getY() + (height / 2), 0);
      rotationMatrix.rotate(0, 0, 1, angle);
      rotationMatrix.translate(
          -(_textField.getX() + (width / 2)), -(_textField.getY() + (height / 2)), 0);

      FlxG.batch.setTransformMatrix(rotationMatrix);
    }

    // blending
    if (blend != null && currentBlend != blend) {
      int[] blendFunc = BlendMode.getOpenGLBlendMode(blend);
      FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]);
    } else if (Gdx.graphics.isGL20Available() && (FlxG.batchShader == null || ignoreBatchShader)) {
      // OpenGL ES 2.0 shader render
      renderShader();
      // OpenGL ES 2.0 blend mode render
      renderBlend();
    }

    // Render shadow behind the text
    if (_shadow != 0) {
      // tinting
      int tintColor = FlxU.multiplyColors(_shadow, camera.getColor());
      _textField.setColor(
          ((tintColor >> 16) & 0xFF) * 0.00392f,
          ((tintColor >> 8) & 0xFF) * 0.00392f,
          (tintColor & 0xFF) * 0.00392f,
          ((_shadow >> 24) & 0xFF) * _alpha * 0.00392f);
      _textField.translate(_shadowX, _shadowY);
      _textField.draw(FlxG.batch);
      _textField.translate(-_shadowX, -_shadowY);
    }

    // tinting
    int tintColor = FlxU.multiplyColors(_color, camera.getColor());
    _textField.setColor(
        ((tintColor >> 16) & 0xFF) * 0.00392f,
        ((tintColor >> 8) & 0xFF) * 0.00392f,
        (tintColor & 0xFF) * 0.00392f,
        _alpha);

    _textField.draw(FlxG.batch);

    // rotation
    if (angle != 0) FlxG.batch.setTransformMatrix(_matrix);

    _VISIBLECOUNT++;

    if (FlxG.visualDebug && !ignoreDrawDebug) drawDebug(camera);
  }