Exemple #1
1
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    Projectile proj;
    playerNextPos = inputHandler.playerInput(player, container.getInput(), delta, sound);
    entity.update(delta, sound);
    if (!isBlocked(playerNextPos, player.getWidth(), player.getHeight())) {
      player.setCoord(playerNextPos);
    }

    player.logic();

    for (int i = 0; i < projectiles.size(); i++) {
      proj = projectiles.get(i);
      proj.update(delta);
      if (isBlocked(proj.pos, proj.getWidth(), proj.getHeight())) {
        projectiles.remove(i);
        sound.playSound(collisionSound);
      } else if (proj.collidesWith(entity) && proj.getOwner() == player) {
        proj.damage(entity);
        projectiles.remove(i);
      } else if (proj.collidesWith(player) && proj.getOwner() == entity) {
        proj.damage(player);
        projectiles.remove(i);
      }
    }
  }
  @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;
  }