class RTanque::Bot::Radar
Constants
- Reflection
A
Reflection
is the information obtained for a bot detected by {RTanque::Bot::Radar}@attr_reader [RTanque::Heading] heading @attr_reader [Float] distance @attr_reader [String] name
- VISION_RANGE
Public Class Methods
new(bot, heading)
click to toggle source
# File lib/rtanque/bot/radar.rb, line 21 def initialize(bot, heading) @bot = bot @heading = heading @reflections = [] end
Public Instance Methods
can_detect?(other_bot)
click to toggle source
# File lib/rtanque/bot/radar.rb, line 49 def can_detect?(other_bot) VISION_RANGE.include?(Heading.delta_between_points(self.position, self.heading, other_bot.position)) end
each(&block)
click to toggle source
# File lib/rtanque/bot/radar.rb, line 31 def each(&block) @reflections.each(&block) end
empty?()
click to toggle source
# File lib/rtanque/bot/radar.rb, line 35 def empty? self.count == 0 end
position()
click to toggle source
# File lib/rtanque/bot/radar.rb, line 27 def position @bot.position end
scan(bots)
click to toggle source
# File lib/rtanque/bot/radar.rb, line 39 def scan(bots) @reflections.clear bots.each do |other_bot| if self.can_detect?(other_bot) @reflections << Reflection.new_from_points(self.position, other_bot.position) { |reflection| reflection.name = other_bot.name } end end self end