/** * Returns a list of all the items in this manager that are within a certain radius of the * provided location. * * @param center The location to search from * @param radius The distance away from the location to select items * @return List of items that are in the area */ public List<T> getInArea(Location3D center, double radius) { Map<Double, T> sortedItems = new TreeMap<Double, T>(); for (T single : myGameSprites) { if (!single.isVisible()) { continue; } // Do basic test first if (single.getWorldLocation().getManhattanDistance(center) < radius) { // Do accurate test second double distance = single.getWorldLocation().getDistance(center); if (distance < radius) { sortedItems.put(distance, single); } } } return new ArrayList<T>(sortedItems.values()); }
/** * Adds items to the manager. These items will then be observed by the NodeMap and will be updated * and painted every cycle. * * @param gs The item to add */ public void add(T gs) { gs.addObserver(GameState.getMap().getNodeMap()); gs.setChanged(); gs.notifyObservers(gs.getWorldLocation()); myGameSprites.add(gs); }