Module: Brawl::BasicScanner

Defined in:
lib/brawl/parts/basic_scanner.rb

Constant Summary collapse

DECIMAL_PLACES =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#angle_maxObject (readonly)

Returns the value of attribute angle_max.



4
5
6
# File 'lib/brawl/parts/basic_scanner.rb', line 4

def angle_max
  @angle_max
end

#scan_maxObject (readonly)

Returns the value of attribute scan_max.



4
5
6
# File 'lib/brawl/parts/basic_scanner.rb', line 4

def scan_max
  @scan_max
end

Instance Method Details

#initialize(params = {}) ⇒ Object



8
9
10
11
# File 'lib/brawl/parts/basic_scanner.rb', line 8

def initialize(params={})
  @scan_max   = params[:scan_max] || 10
  @angle_max  = params[:angle_max] || 45
end

#scan(params = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/brawl/parts/basic_scanner.rb', line 13

def scan(params={})
  angle = [@angle_max, params[:angle] ||= @angle_max].min

  cone = {
    origin:     @location,
    direction:  params[:direction],
    radius:     @scan_max,
    angle:      angle,
  }

  @arena.get_all_objects.collect do |info_hash|
    next if info_hash[:id] == @id 
    if obj = Helper.point_in_cone?(cone.merge(point: info_hash[:location]))
      info_hash.merge(obj)
    end
  end.compact
  
end