lib/traits/targeting/closest.rb in gosu_extensions-0.2.5 vs lib/traits/targeting/closest.rb in gosu_extensions-0.2.6

- old
+ new

@@ -7,20 +7,10 @@ # Returns the closest target of all targets in the fire arc. # # TODO fire arc # def acquire *targets - closest = nil - lowest_distance = nil - - targets.each do |target| - distance = (target.position - self.position).length - next if lowest_distance && distance > lowest_distance - lowest_distance = distance - closest = target - end - - closest + targets.sort_by {|target| distance = (target.position - self.position).length }.first end end end \ No newline at end of file