Sha256: 013ed6a32ea71f205ba61701a3cdc76d88a0f963ed23ac886ddf3986ae1190cf

Contents?: true

Size: 539 Bytes

Versions: 15

Compression:

Stored size: 539 Bytes

Contents

# Use this if you need a closest targeting mechanism.
#
module Targeting
  
  module Closest
    
    # 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
    end
  end
  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gosu_extensions-0.1.14 lib/traits/targeting/closest.rb
gosu_extensions-0.1.13 lib/traits/targeting/closest.rb
gosu_extensions-0.1.12 lib/traits/targeting/closest.rb
gosu_extensions-0.1.11 lib/traits/targeting/closest.rb
gosu_extensions-0.1.10 lib/traits/targeting/closest.rb
gosu_extensions-0.1.9 lib/traits/targeting/closest.rb
gosu_extensions-0.1.8 lib/traits/targeting/closest.rb
gosu_extensions-0.1.7 lib/traits/targeting/closest.rb
gosu_extensions-0.1.6 lib/traits/targeting/closest.rb
gosu_extensions-0.1.5 lib/traits/targeting/closest.rb
gosu_extensions-0.1.4 lib/traits/targeting/closest.rb
gosu_extensions-0.1.3 lib/traits/targeting/closest.rb
gosu_extensions-0.1.2 lib/traits/targeting/closest.rb
gosu_extensions-0.1.1 lib/traits/targeting/closest.rb
gosu_extensions-0.1.0 lib/traits/targeting/closest.rb