Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Tower bug fix #234

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading