public Vector2d getForceFor(MovingEntity be) {
    Vector2d currentVector = be.getCurrentVelocity();

    double force = (1 - m_ForceScalar) / 25;

    if (m_ForceScalar > 1) force /= 5;

    force /= be.getMass();

    currentVector.scale(force * -1);

    return currentVector;
  }
Exemplo n.º 2
0
  // ----------------------------- Update -----------------------------------
  //
  // updates the ball physics, tests for any collisions and adjusts
  // the ball's velocity accordingly
  // ------------------------------------------------------------------------
  public void update(float tpf) {
    // keep a record of the old position so the goal::scored method
    // can utilize it for goal testing
    if (position != null) {
      oldPos.cloneVec(position);
    }
    // Test for collisions
    testCollisionWithWalls(pitchBoundary);

    // Simulate Params.Instance().Friction. Make sure the speed is positive
    // first though
    double friction = Params.Instance().Friction;
    // println (velocity)
    // println("LengthSq" + velocity.LengthSq() +" friction " + friction)
    if (velocity.LengthSq() > friction * friction) {
      velocity = velocity.plus(Vec2DNormalize(velocity).multiply(friction));
      // println (velocity)
      position = position.plus(velocity.multiply(tpf));
      // println (position)
      // update heading
      heading = Vec2DNormalize(velocity);
    }

    super.update(tpf);
  }
Exemplo n.º 3
0
 /**
  * Renders the given entity
  *
  * @param camera Camera which is used to render the entity
  */
 @Override
 public void render(Camera camera, float delta) {
   super.render(camera, delta);
   if (Gdx.input.isTouched()) {
     Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
     camera.unproject(touchPos);
     setDestination(new Vector2(touchPos.x - 24 / 2, touchPos.y - 24 / 2));
   }
   setHeading(new Vector2(destination).sub(position).nor());
 }