/** * Find an element near a given one.<br> * WARNING: it's an unoptimized method, contrary to {@link #collideSprite(int, int, Element)}, but * it's used only once when player press action key. So it's acceptable now. * * @param x * @param y * @param quelElement * @param radius * @return Element */ public Element collideElement( int x, int y, Element quelElement, int radius, SpriteDescription... expectedDesc) { Perso perso = null; if (quelElement != null && quelElement.getEntityType().isPerso()) { perso = (Perso) quelElement; } for (SpriteEntity entity : spriteEntities) { if (entity.getEntityType().isElement()) { if (entity != quelElement) { int tx = (int) entity.x; int ty = (int) entity.y; if (EngineZildo.collideManagement.checkCollisionCircles(x, y, tx, ty, radius, radius)) { if (perso != null && perso.isZildo() && perso.linkedSpritesContains(entity)) { // Collision between hero and object he's carrying => let it go } else if (quelElement == null || quelElement.getLinkedPerso() != entity) { // Check that found element is one of expected ones if (expectedDesc != null && expectedDesc.length > 0) { for (SpriteDescription sDesc : expectedDesc) { if (sDesc == entity.getDesc()) { return (Element) entity; } } continue; // Check next one } Element elem = (Element) entity; // Found an element, but is it really the most pertinent ? (ex:shadow) if (elem.getLinkedPerso() != null) { return elem.getLinkedPerso(); } return elem; } } } } } return null; }