Hover unit display

This commit is contained in:
Anuken
2020-06-16 22:56:51 -04:00
parent 0aa313e37c
commit 5da0267df9
9 changed files with 144 additions and 95 deletions

View File

@@ -180,6 +180,25 @@ public class Units{
return result;
}
/** Returns the closest ally of this team. Filter by predicate.
* Unlike the closest() function, this only guarantees that unit hitboxes overlap the range. */
public static Unitc closestOverlap(Team team, float x, float y, float range, Boolf<Unitc> predicate){
result = null;
cdist = 0f;
nearby(team, x - range, y - range, range*2f, range*2f, e -> {
if(!predicate.get(e)) return;
float dist = e.dst2(x, y);
if(result == null || dist < cdist){
result = e;
cdist = dist;
}
});
return result;
}
/** Iterates over all units in a rectangle. */
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
teamIndex.tree(team).intersect(height, x, y, width, cons);