Skip to content

Commit

Permalink
Fixed Tower Build Bug. Closes #223
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamad11Dab committed Oct 5, 2023
1 parent 5488c94 commit 962fa12
Showing 1 changed file with 19 additions and 1 deletion.
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

0 comments on commit 962fa12

Please sign in to comment.