Sha256: 540d147d3a1f047727f16f832516e57758b33c910bdab638864bc5e69df65fb9

Contents?: true

Size: 552 Bytes

Versions: 20

Compression:

Stored size: 552 Bytes

Contents

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

20 entries across 20 versions & 1 rubygems

Version Path
gosu_extensions-0.2.5 lib/traits/targeting/closest.rb
gosu_extensions-0.2.4 lib/traits/targeting/closest.rb
gosu_extensions-0.2.3 lib/traits/targeting/closest.rb
gosu_extensions-0.2.2 lib/traits/targeting/closest.rb
gosu_extensions-0.2.1 lib/traits/targeting/closest.rb
gosu_extensions-0.2.0 lib/traits/targeting/closest.rb
gosu_extensions-0.1.28 lib/traits/targeting/closest.rb
gosu_extensions-0.1.27 lib/traits/targeting/closest.rb
gosu_extensions-0.1.26 lib/traits/targeting/closest.rb
gosu_extensions-0.1.25 lib/traits/targeting/closest.rb
gosu_extensions-0.1.24 lib/traits/targeting/closest.rb
gosu_extensions-0.1.23 lib/traits/targeting/closest.rb
gosu_extensions-0.1.22 lib/traits/targeting/closest.rb
gosu_extensions-0.1.21 lib/traits/targeting/closest.rb
gosu_extensions-0.1.20 lib/traits/targeting/closest.rb
gosu_extensions-0.1.19 lib/traits/targeting/closest.rb
gosu_extensions-0.1.18 lib/traits/targeting/closest.rb
gosu_extensions-0.1.17 lib/traits/targeting/closest.rb
gosu_extensions-0.1.16 lib/traits/targeting/closest.rb
gosu_extensions-0.1.15 lib/traits/targeting/closest.rb