Ejemplo n.º 1
0
  void playerControl(LudumDare26Game.ControlsState controlsState) {
    boolean doStop = !(controlsState.leftPressed || controlsState.rightPressed);

    final Body body = getBody();
    float linearDamping = 0;
    if (doStop) {
      body.setAngularVelocity(0);
      //                linearDamping = 10f;
      Vec2 linearVelocity = body.getLinearVelocity();
      linearVelocity.x *= 0.9;
      //                body.applyForce(new Vec2(v, 0), body.getPosition());
      body.setLinearVelocity(linearVelocity);
    } else {
      Vec2 linearVelocity = body.getLinearVelocity();
      final int dir = (controlsState.leftPressed ? -1 : 0) + (controlsState.rightPressed ? 1 : 0);
      float v = linearVelocity.x;
      v += dir * MOVE_ACC;
      v = Math.max(-MOVE_SPEED, Math.min(v, MOVE_SPEED));
      linearVelocity.x = v;
      //                body.applyForce(new Vec2(v, 0), body.getPosition());
      body.setLinearVelocity(linearVelocity);
      //                linearDamping = 1f;
    }
    body.setLinearDamping(linearDamping);
  }
Ejemplo n.º 2
0
Archivo: Body.java Proyecto: rdo/speleo
 /**
  * Set the linear velocity of this body
  *
  * @param xVelocity The x component of the velocity
  * @param yVelocity The y component of the velocity
  */
 public void setVelocity(float xVelocity, float yVelocity) {
   checkBody();
   Vec2 vel = jboxBody.getLinearVelocity();
   vel.x = xVelocity;
   vel.y = yVelocity;
   jboxBody.setLinearVelocity(vel);
 }
  @Override
  public void move(Body body) {
    Objects.requireNonNull(body);

    if (body.getLinearVelocity().x == 0) {
      Vec2 v2 = new Vec2(2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
    if (body.getPosition().x * EscapeWorld.SCALE >= 550) {
      Vec2 v2 = new Vec2(-2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
    if (body.getPosition().x * EscapeWorld.SCALE <= 90) {
      Vec2 v2 = new Vec2(2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
  }
Ejemplo n.º 4
0
Archivo: Body.java Proyecto: rdo/speleo
 /**
  * Get the Y velocity of the body
  *
  * @return The y velocity of the body
  */
 public float getYVelocity() {
   checkBody();
   return jboxBody.getLinearVelocity().y;
 }
 private void dampenLiquid() {
   for (int i = 0; i < liquid.length; ++i) {
     Body b = liquid[i];
     b.setLinearVelocity(b.getLinearVelocity().mul(0.995f));
   }
 }