diff --git a/source/core/src/main/com/csse3200/game/entities/EntityService.java b/source/core/src/main/com/csse3200/game/entities/EntityService.java index b5fe3ce77..f45576fb0 100644 --- a/source/core/src/main/com/csse3200/game/entities/EntityService.java +++ b/source/core/src/main/com/csse3200/game/entities/EntityService.java @@ -183,6 +183,24 @@ public Entity getEntityAtPosition(float x, float y) { return null; } + /** + * Checks for the presence of an Entity at a specified position (x, y). + * + * @param x The x-coordinate of the position to check. + * @param y The y-coordinate of the position to check. + * @return The Entity found at the specified position, or null if no Entity is present. + */ + public Entity checkEntityAtPosition(int x, int y) { + entities.sort(Comparator.comparingInt(Entity::getLayer)); + for (Entity entity : entities) { + if (entity.getPosition().x == x && entity.getPosition().y == y) { + return entity; + } + } + return null; + } + + private boolean entityContainsPosition(Entity entity, float x, float y) { float entityX = entity.getPosition().x; float entityY = entity.getPosition().y; @@ -207,7 +225,7 @@ public boolean entitiesInTile(int x_coord, int y_coord) { return true; } if (mp.getCell(x_coord, y_coord) != null) { - Entity entity = getEntityAtPosition(x_coord, y_coord); + Entity entity = checkEntityAtPosition(x_coord, y_coord); return entity != null; } return true;