Esempio n. 1
0
 /**
  * Handles the keyboard input.
  *
  * @param elapsed time elapsed since the last frame
  */
 private void handleControllerInput(float elapsed) {
   if (controllerActive) {
     if (controller.justPressed(KeyEvent.VK_A)) {
       simpleAttack();
     }
     if (state == DynamicObjectState.Attacking) {
       curAnim.update(elapsed);
       return;
     } else if (controller.justPressed(KeyEvent.VK_S)) spellAttack(0);
     else if (controller.justPressed(KeyEvent.VK_D)) spellAttack(1);
     else if (controller.justPressed(KeyEvent.VK_F)) spellAttack(2);
     else if (controller.justPressed(KeyEvent.VK_5)) spellManager.activateShield(ElementType.Fire);
     else if (controller.justPressed(KeyEvent.VK_6))
       spellManager.activateShield(ElementType.Water);
     else if (controller.justPressed(KeyEvent.VK_7))
       spellManager.activateShield(ElementType.Earth);
     else if (controller.isDownPressed()) move(Heading.Down);
     else if (controller.isUpPressed()) move(Heading.Up);
     else if (controller.isLeftPressed()) move(Heading.Left);
     else if (controller.isRightPressed()) move(Heading.Right);
     else if (controller.justReleased(KeyEvent.VK_LEFT)
         || controller.justReleased(KeyEvent.VK_RIGHT)
         || controller.justReleased(KeyEvent.VK_UP)
         || controller.justReleased(KeyEvent.VK_DOWN)) stopMovement();
     else if (controller.justPressed(KeyEvent.VK_ENTER)) collision.checkOnKeyTriggers(this);
   }
 }
Esempio n. 2
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);
      }
    }
  }
Esempio n. 3
0
  /**
   * Creates an instace of the player from an actorDescription.
   *
   * @param game instance of the game running
   * @param desc the ActorDescription
   * @param position the position in screenspace
   * @param controllerActive indicates if the player should be controlled by the keyboard
   * @param actID the actorID to be given. This is only done in network-games
   */
  public Player(
      Game game, ActorDescription desc, Vector2 position, boolean controllerActive, int actID) {
    super(game, desc, position);

    this.actorID = actID;

    this.state = DynamicObjectState.Idle;
    this.velocity = new Vector2(0, 0);
    this.game = game;

    controller = game.getController();
    statsMenu = new StatsMenu(stats, controller, this);
    statusbar = new StatusBar(this, game);
    inventory.setGold(25);

    // TEST
    spellManager = new SpellManager(this);
    spellManager.addShields();

    initAnimations();

    // DEBUG
    skillTree = new SkillTree(this, controller, collision);
    buildSpell();
    this.controllerActive = controllerActive;
    controlled = controllerActive;
    isInNetwork = game.isInNetwork();
    posState = new PositionState(this);
  }
Esempio n. 4
0
 @Override
 public void levelUp() {
   health.fillHealth();
   mana.fillMana();
   statsMenu.leveledUp();
   spellManager.addShields();
 }
Esempio n. 5
0
  @SuppressWarnings("incomplete-switch")
  @Override
  public void draw(Graphics2D graphics) {
    ElementalShield cs = spellManager.getCurrentShield();
    if (cs != null) {
      Color[] c = new Color[3];
      c[0] = new Color(0, 0, 0, 0);
      c[1] = new Color(0, 0, 0, 0);
      ElementType type = cs.getElementType();

      switch (type) {
        case Earth:
          c[2] = new Color(0.45f, 0.4f, 0.15f, 0.85f);
          break;
        case Fire:
          c[2] = new Color(1.0f, 0.0f, 0.0f, 0.7f);
          break;
        case Water:
          c[2] = new Color(0.3f, 0.3f, 0.8f, 0.7f);
          break;
      }

      float[] dist = {0.0f, 0.25f, 1f};
      RadialGradientPaint rgp =
          new RadialGradientPaint(
              new Point2D.Float((int) screenPosition.x + 16, (int) screenPosition.y + 16),
              20,
              dist,
              c);
      graphics.setPaint(rgp);
      graphics.fillOval((int) screenPosition.x - 4, (int) screenPosition.y - 4, 40, 40);
    }

    graphics.drawImage(getTexture(), (int) screenPosition.x, (int) screenPosition.y, null);
    if (controlled) {
      spellManager.draw(graphics);
      statusbar.draw(graphics);
    }

    if (isInNetwork && controllerActive) {
      if (controller.isPressed(KeyEvent.VK_T)) DeathMatchStatistics.getInstance().draw(graphics);
    }
  }
Esempio n. 6
0
  @Override
  public void update(float elapsed) {
    if (!isInNetwork && health.isDead()) {
      terminate();
      return;
    }

    regenerate();
    spellManager.update(elapsed);

    ElementalShield curShield = spellManager.getCurrentShield();
    if (curShield != null && curShield.getElementType() == ElementType.Fire)
      manager.handleAreaOfEffectSpell(
          this, curShield.getDamage(), ElementType.Fire, curShield.getAOErect());

    if (state == DynamicObjectState.Attacking) {
      curAnim.update(elapsed);
      return;
    }

    if (state == DynamicObjectState.Hit) {
      curAnim.update(elapsed);
      curHitDuration -= 1;
      if (curHitDuration <= 0) {
        setState(DynamicObjectState.Idle);
        curHitDuration = maxHitDuration;
        health.setInvul(false);
      }

      return;
    }

    if (controllerActive) handleControllerInput(elapsed);

    // DEBUG PURPOSE
    if (controllerActive) {
      if (controller.isPressed(KeyEvent.VK_SHIFT)) supressEnemyCollision = true;
      else supressEnemyCollision = false;
    }
    // -------------

    if (velocity.x > 0.01f || velocity.x < -0.01f || velocity.y > 0.01f || velocity.y < -0.01f) {
      collisionRect.x += velocity.x;
      collisionRect.y += velocity.y;

      boolean collidingStatic = collision.isCollidingStatic(this);
      boolean collidingDynamic = false;
      if (!supressEnemyCollision) collidingDynamic = collision.isCollidingDynamic(this);

      if (collidingStatic || collidingDynamic) {
        collisionRect.x -= velocity.x;
        collisionRect.y -= velocity.y;
        stopMovement();
      } else {
        collision.checkTriggers(this);
        screenPosition.x += velocity.x;
        screenPosition.y += velocity.y;
        curAnim.update(elapsed);
      }
    }

    if (isInNetwork && controllerActive) {
      sendPositionMessage();
    }
  }
Esempio n. 7
0
 /** Creates all spells. */
 private void buildSpell() {
   spellManager.addSpell(skillTree.getFireSkills().get(0).getSpell());
   spellManager.addSpell(skillTree.getWaterSkills().get(0).getSpell());
   spellManager.addSpell(skillTree.getEarthSkills().get(0).getSpell());
 }
Esempio n. 8
0
 /** Updates MaxHealth and MaxMana after a change in stats. */
 public void renewHealthMana() {
   health.setMaxHealh(stats.getStamina() * Stats.HEALTH_PER_STAM);
   mana.setMaxMana(stats.getWill() * Stats.MANA_PER_WILL);
   spellManager.addShields();
 }