예제 #1
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);
  }
예제 #2
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);
  }
예제 #3
0
 public static Weapon load(String id) {
   Weapon w;
   Json j = new Json(OutputType.json);
   w = j.fromJson(Weapon.class, Gdx.files.internal("core/assets/json/weapons/" + id + ".json"));
   w.weaponID = id;
   return w;
 }
예제 #4
0
  @Override
  public void dispose() {
    characterController.dispose();
    ghostObject.dispose();
    actionZone.dispose();

    leftweapon.dispose();
    rightweapon.dispose();
  }
예제 #5
0
 public void iterateClass(int i) {
   int newClassID = classtype.getID() + i;
   newClassID = (newClassID + P.Class.LENGTH) % P.Class.LENGTH;
   classtype = P.Class.getFromID(newClassID);
   rightweapon.dispose();
   rightweapon = Weapon.load(classtype.getRightHandWeapon());
   leftweapon.dispose();
   leftweapon = Weapon.load(classtype.getLeftHandWeapon());
   loadWeaponModels();
   updateBaseStats();
 }
예제 #6
0
 /**
  * Helper method makes simple scrollable panel full of possible responses.
  *
  * @param c Character accused
  * @param w Weapon accused
  * @param r Room accused
  * @return scroll panel of buttons
  */
 private JScrollPane cardsPanel(Character c, Weapon w, Room r) {
   JPanel panel = new JPanel(new FlowLayout()); // perhaps boxlayout along x
   JScrollPane pane =
       new JScrollPane(
           panel,
           JScrollPane.VERTICAL_SCROLLBAR_NEVER,
           JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   for (Card crd : player.getCards()) {
     if (crd.toString().equals(c.getName())
         || crd.toString().equals(w.getName())
         || crd.toString().equals(r.toString())) {
       refutable = true;
       JButton l = new JButton(new ImageIcon(crd.getCardImg()));
       final Card refW = crd;
       l.addActionListener(
           new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent arg0) {
               refutedWith = refW;
             }
           });
       l.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
       l.setBorder(new EmptyBorder(10, 10, 10, 10));
       panel.add(l);
     }
   }
   return pane;
 }
예제 #7
0
 public void updateWeaponInstances() {
   float time = 0;
   if (animations.current != null) {
     time = animations.current.time / animations.current.duration;
   }
   rightweapon.mi.transform.set(mi.transform);
   rightweapon.mi.transform.translate(-0.31943f, 0, 0.25910f); // translate weapon to shoulder
   if (isPerformingRightAction) {
     rightweapon.mi.transform.translate(0, 0, -0.37f);
     rightweapon.updateAnim(rightActionTimer);
   } else {
     rightweapon.mi.transform.rotate(
         1,
         0,
         0,
         (float)
             (30f * MathUtils.sinDeg(360 * time))); // rotate weapon according to walking animation
     rightweapon.mi.transform.translate(0, 0, -0.37f);
   }
   if (rightweapon.hasParticles) {
     rightweapon.magicParticles.setTransform(rightweapon.mi.transform);
     rightweapon.magicParticles.translate(new Vector3(0, -0.2f, 0));
   }
   leftweapon.mi.transform.set(mi.transform);
   leftweapon.mi.transform.translate(0.31943f, 0, 0.25910f); // translate weapon to shoulder
   leftweapon.mi.transform.rotate(
       1,
       0,
       0,
       (float)
           (-30f * MathUtils.sinDeg(360 * time))); // rotate weapon according to walking animation
   leftweapon.mi.transform.translate(0, 0, -0.37f); // move weapon to hand
   //     leftweapon.mi.transform.translate(0.31943f, 0, -0.07091f);
   if (isPerformingLeftAction) {
     leftweapon.updateAnim(leftActionTimer);
   }
   if (leftweapon.hasParticles) {
     leftweapon.magicParticles.setTransform(leftweapon.mi.transform);
     leftweapon.magicParticles.translate(new Vector3(0, -0.2f, 0));
   }
 }
예제 #8
0
 @Override
 public void render(ModelBatch b, Environment e) {
   b.render(mi, e);
   rightweapon.render(b, e);
   leftweapon.render(b, e);
 }
예제 #9
0
 void loadWeaponModels() {
   rightweapon.dispose();
   leftweapon.dispose();
   rightweapon.loadModel(a, this);
   leftweapon.loadModel(a, this);
 }