Ejemplo n.º 1
0
  /**
   * Tries to cast the spell with the given index. Checks cooldown and manacosts.
   *
   * @param index
   */
  public void spellAttack(int index) {
    if (state == DynamicObjectState.Attacking) return;

    curAnim = idleAnim.get(heading);
    Vector2 spVelo = new Vector2();
    Vector2 startPos = new Vector2();
    if (heading == Heading.Right) {
      spVelo.x = spSpeed;
      startPos = new Vector2(collisionRect.x + collisionRect.width, collisionRect.y);
    } else if (heading == Heading.Left) {
      spVelo.x = -spSpeed;
      startPos = new Vector2(collisionRect.x - 32, collisionRect.y);
    } else if (heading == Heading.Up) {
      spVelo.y = -spSpeed;
      startPos = new Vector2(collisionRect.x, collisionRect.y - 32);
    } else {
      spVelo.y = spSpeed;
      startPos = new Vector2(collisionRect.x, collisionRect.y + (float) collisionRect.getHeight());
    }

    Spell curSpell = spellManager.getSpell(index);
    if (!curSpell.isOnCooldown() && mana.getCurrentMana() >= curSpell.getManaCost()) {
      mana.reduceMana(curSpell.getManaCost());
      manager.spawnSpell(curSpell.getProjectile(startPos, heading));
      spellManager.activate(index);
      if (isInNetwork && controllerActive) {
        NetworkManager.sendSpellMessage(this, index);
      }
    }
  }
Ejemplo n.º 2
0
  /** The player will perform a simple MeleeAttack. */
  public void simpleAttack() {
    if (state == DynamicObjectState.Attacking) return;

    state = DynamicObjectState.Attacking;

    if (!isInNetwork) {
      curAnim = simpleAttack.getAnimation(heading);
      manager.registerAttack(simpleAttack);
      simpleAttack.activate();
    } else {
      NetworkManager.sendAttackMessage(this);
    }
  }
Ejemplo n.º 3
0
  /** Sends a PositionMessage in a networkgame if needed. */
  private void sendPositionMessage() {
    if (posState.equals(this)) return;

    posState.update(this);
    NetworkManager.sendPositionMessage(this);
  }