Exemplo n.º 1
0
  public static Projectile fire() {
    if (System.currentTimeMillis() < readyToFire) {
      return null;
    } else {
      readyToFire = System.currentTimeMillis() + delayMillis;
      Projectile p = new Projectile(X(), Y(), right, currentDamage, currentKnockback);
      if (right) p.range = gw.getRightBound(X(), Y()) - X();
      else p.range = X() - gw.getLeftBound(X(), Y());
      for (int i = 0; i < 5; i++) p.update();

      return p;
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean checkMobProjectileHit(Projectile p) {
    if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) {
      Monster monster = null;

      try {
        for (String key : monsters.keySet()) {
          monster = (Monster) monsters.get(key);
          if (monster.getPerimeter().intersects(p.getRect())) {
            monster.applyDamage(p.getDamage(), p.getSource(), p.isFromPlaceable());
            return true;
          }
        }
      } catch (ConcurrentModificationException concEx) {
        // another thread was trying to modify monsters while iterating
        // we'll continue and the new item can be grabbed on the next update
      }
    }

    return false;
  }