Skip to content

Commit

Permalink
Merge pull request #234 from UQcsse3200/Mohamad-Maps
Browse files Browse the repository at this point in the history
Build Tower bug fix
  • Loading branch information
Hasakev authored Oct 6, 2023
2 parents 3e31d95 + a174583 commit 7d8efa9
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 7d8efa9

Please sign in to comment.