Class: Radar

Inherits:
Object
  • Object
show all
Defined in:
lib/entities/radar.rb

Constant Summary collapse

UPDATE_FREQUENCY =
1000
WIDTH =
150
HEIGHT =
100
PADDING =
10
BACKGROUND =

Black with 33% transparency

Gosu::Color.new(255 * 0.33, 0, 0, 0)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_pool, target) ⇒ Radar

Returns a new instance of Radar.



10
11
12
13
14
# File 'lib/entities/radar.rb', line 10

def initialize(object_pool, target)
  @object_pool = object_pool
  @target = target
  @last_update = 0
end

Instance Attribute Details

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/entities/radar.rb', line 8

def target
  @target
end

Instance Method Details

#drawObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/entities/radar.rb', line 25

def draw
  x1, x2, y1, y2 = radar_coords
  $window.draw_quad(
    x1, y1, BACKGROUND,
    x2, y1, BACKGROUND,
    x2, y2, BACKGROUND,
    x1, y2, BACKGROUND,
    200)
  draw_tank(@target, Gosu::Color::GREEN)
  @nearby && @nearby.each do |t|
    draw_tank(t, Gosu::Color::RED)
  end
end

#updateObject



16
17
18
19
20
21
22
23
# File 'lib/entities/radar.rb', line 16

def update
  if Gosu.milliseconds - @last_update > UPDATE_FREQUENCY
    @nearby = nil
  end
  @nearby ||= @object_pool.nearby(@target, 2000).select do |o|
    o.class == Tank && !o.health.dead?
  end
end