コード例 #1
0
  public void handleInput(InputState pInputState) {
    if (mControllingCharacter == null) return;

    if (pInputState.mouseLeftClick() && mAttackTimer > mControllingCharacter.attackSpeed()) {
      mAttackVector.x = pInputState.mouseScreenCoords().x;
      mAttackVector.y = pInputState.mouseScreenCoords().y;
      mAttack = true;
      mAttackTimer = 0;
    }
  }
コード例 #2
0
  public void update(GameTime pGameTime) {

    mAttackTimer += pGameTime.elapseGameTime();

    if (mAttack) {
      Vector2f lDirection =
          new Vector2f(
              mAttackVector.x + mGameWorldScreen.gameCamera().getPosition().x - 400,
              mAttackVector.y + mGameWorldScreen.gameCamera().getPosition().y - 320);
      float ltx = mControllingCharacter.x() + mControllingCharacter.width() * .5f;
      float lty = mControllingCharacter.y() + mControllingCharacter.height() * .5f;
      lDirection.sub(ltx, lty);
      lDirection.nor();

      lDirection.mul(10f);

      mGameWorldScreen
          .fireBallParticles()
          .addParticle(ltx, lty, lDirection.x, lDirection.y, new Sprite(0, 0, 32, 32));
      mAttack = false;
    }
  }