コード例 #1
0
  /** Resets the widget to start state. */
  public void resetWidget() {
    // Reset has been made, so we CAN activate this later.
    reset = true;
    // Make inactive
    active = false;
    // Not collided.
    collided = false;

    bounces = 0;
    currentDirection = direction;
    image = frames.get(0);
    body.setEnabled(false);
    // Move to initial position.
    body.set(shape, MASS);
    body.setPosition(position.x + WIDTH / 2, position.y + HEIGHT / 2);

    // Make sure the gameplay didn't mess with any initial properties.
    body.setCanRest(true);
    body.setDamping(0.0f);
    body.setFriction(0.01f);
    body.setGravityEffected(false);
    body.setIsResting(true);
    body.setMoveable(true);
    body.setRestitution(1.5f);
    body.setRotatable(true);
    body.setRotation(0.0f);
    body.setRotDamping(0.0f);
    body.setMaxVelocity(50f, 50f);
    body.setForce(-body.getForce().getX(), -body.getForce().getY());
    if (currentDirection == Direction.WEST) {
      body.setForce(-MOVEMENT_SPEED, 0);
    } else if (currentDirection == Direction.EAST) {
      body.setForce(MOVEMENT_SPEED, 0);
    }
    if (currentDirection == Direction.NORTH) {
      body.setForce(0, -MOVEMENT_SPEED);
    } else if (currentDirection == Direction.SOUTH) {
      body.setForce(0, MOVEMENT_SPEED);
    }
    body.adjustVelocity(new Vector2f(-body.getVelocity().getX(), -body.getVelocity().getY()));
    body.adjustAngularVelocity(-body.getAngularVelocity());
  }
コード例 #2
0
 /**
  * Set the position of the widget.
  *
  * @param f The x,y coordinates within the container.
  */
 public void setPosition(Vector2f f) {
   body.setPosition(f.x + WIDTH / 2, f.y + HEIGHT / 2);
   position = f;
 }