//-1 for maxRange if it doesnt matter internal List<Moveable> getClosestPlayers(Vector2f v,int amt, bool alive, int maxRange, Type ignoreClass) { double[] lengths = new double[amt]; for (int i = 0; i < lengths.Length;i++ ) {//populate with "big" number lengths[i] = 9999; } Moveable[] players = new Moveable[amt]; foreach (Moveable m in moveables) {//go thru every player if (m is PlayerClassI) { if (ignoreClass == m.GetType() || (alive && m.isDead())) continue; double length = getDistance(v, m.getMid()); if(maxRange != -1 && length > maxRange) continue;//if hes too far, continue for (int i = 0; i < amt;i++ ) {//if not start placing him somewhere if (length < lengths[i]) {//if here //push everything down for (int j = amt - 1; j != i; j-- ) { lengths[j] = lengths[j - 1]; players[j] = players[j - 1]; } //then place lengths[i] = length; players[i] = m; break; } } } } return players.ToList<Moveable>(); }