Ejemplo n.º 1
0
  /**
   * Returns TRUE if given element is colliding something at given location.
   *
   * @param tx
   * @param ty
   * @param quelElement (can be NULL)
   * @param rayon
   * @return boolean
   */
  public Perso checkCollision(int x, int y, Element quelElement, int rayon) {

    int gridX = x >> 4;
    int gridY = y >> 4;
    int fromId = quelElement != null ? quelElement.getId() : -1;
    boolean foreGround = quelElement != null && quelElement.isForeground();

    // Try on given grid case
    Perso perso = locatePerso(gridX, gridY, foreGround, fromId);
    if (perso != null && checkCollisionOnPerso(x, y, quelElement, perso, rayon)) {
      return perso;
    }
    int nbPersoAround = CollBuffer.howManyAround(gridX, gridY);
    if (nbPersoAround <= 1) {
      return null;
    }
    nbPersoAround--;
    if (nbPersoAround != 0) {
      for (Angle a : Angle.values()) {
        Point offset = a.coords;
        int gx = gridX + offset.x;
        int gy = gridY + offset.y;
        perso = locatePerso(gx, gy, foreGround, fromId);
        if (perso != null && checkCollisionOnPerso(x, y, quelElement, perso, rayon)) {
          return perso;
        }
      }
    }
    return null;
  }