示例#1
0
  public Player(Controls input, World w) {
    this.input = input;
    this.w = w;

    classtype = Class.Warrior;
    racetype = Race.Human;
    rightweapon = Weapon.load(classtype.getRightHandWeapon());
    leftweapon = Weapon.load(classtype.getLeftHandWeapon());

    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(new Matrix4());
    w.physicsWorld.getPairCache().setInternalGhostPairCallback(new btGhostPairCallback());
    ghostObject.setCollisionShape(P.PLAYER_SHAPE);
    ghostObject.setCollisionFlags(
        CollisionFlags.CF_CHARACTER_OBJECT | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
    characterController = new btKinematicCharacterController(ghostObject, P.PLAYER_SHAPE, 0.3f);
    ghostObject.setContactCallbackFilter(World.ALL_FLAG ^ World.FLOOR_FLAG);
    w.physicsWorld.addCollisionObject(ghostObject, World.CHARACTER_FLAG, World.ALL_FLAG);
    w.physicsWorld.addAction(characterController);

    //     actionZone = new btCollisionObject();
    //     actionZone.setCollisionShape(new btBoxShape(0,5f, 0,5f, 1f));
    characterController.setUpAxis(3);
    characterController.setMaxSlope(MathUtils.PI / 3);

    updateBaseStats();
    System.out.println("got through player constructor");
    //		w.physicsWorld.addCollisionObject(actionZone);

    face = new Vector3(0, 1, 0);
  }
示例#2
0
  public void update(float delta, Camera c) {

    heal(healthregen * delta);
    regenerateMana(manaregen * delta);

    if (!isJumping && input.isJumpPressed()) {
      characterController.jump();
      animations.setAnimation("Jumping");
      isJumping = true;
    } else {
      isJumping = false;
    }
    if (!isPerformingRightAction && input.isRightHandPressed()) {
      isPerformingRightAction = true;
      rightweapon.onAttackStart();
      rightActionTimer += delta;
    } else if (isPerformingRightAction) {
      rightActionTimer += delta;
      if (rightActionTimer > rightweapon.attacktime) {
        rightActionTimer = 0;
        isPerformingRightAction = false;
        rightweapon.onAttackEnd();
      }
    }
    if (!isPerformingLeftAction && input.isLeftHandPressed()) {
      leftweapon.onAttackStart();
      isPerformingLeftAction = true;
      leftActionTimer += delta;
    } else if (isPerformingLeftAction) {
      leftActionTimer += delta;
      if (leftActionTimer > leftweapon.attacktime) {
        leftActionTimer = 0;
        isPerformingLeftAction = false;
        rightweapon.onAttackEnd();
      }
    }
    Vector3 movement = new Vector3();
    Vector3 back = new Vector3(c.direction.x, c.direction.y, 0).nor();
    back.nor();
    movement.add(back.cpy().scl(input.getForward()));
    movement.add(back.cpy().crs(0, 0, 1).scl(input.getRight()));
    movement.nor();
    movement.scl(input.isSprintPressed() ? 5 : 1);
    characterController.setWalkDirection(movement.cpy().scl(delta * runspeed));

    if (movement.len() != 0) {
      face = movement.cpy().scl(-1);
      if (characterController.canJump()) {
        animations.setAnimation("Walking", -1, 0.4f * movement.len() * runspeed, null);
      }
    } else {
      if (characterController.canJump()) {
        animations.setAnimation(null);
      }
    }
    mi.transform.set(ghostObject.getWorldTransform().translate(0, 0, -0.25f));
    mi.transform.rotate(0, 0, -1, (float) Math.toDegrees(Math.atan2(face.x, face.y)));
    updateWeaponInstances();
    animations.update(delta);
  }
示例#3
0
  @Override
  public void dispose() {
    characterController.dispose();
    ghostObject.dispose();
    actionZone.dispose();

    leftweapon.dispose();
    rightweapon.dispose();
  }
示例#4
0
  public void updateDependents() {
    maxhealth = 2 * tenacity;
    maxmana = (intelligence >= 15) ? (intelligence - 10) : 0;
    runspeed = 2 + celerity / 5;
    jumpheight = (float) Math.log(2 * dexterity + celerity - 15) * 4.5f;
    attackmultiplier = 1 + 0.1f * (strength - 10);
    critchance = (float) (1 / (2 + Math.exp(3 - (dexterity / 9))));

    actualhealth = maxhealth;
    actualmana = maxmana;

    healthregen = maxhealth * 0.07f;
    manaregen = maxmana * 0.07f;

    characterController.setMaxJumpHeight(jumpheight);
  }