Class: HUD

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_pool, tank) ⇒ HUD

Returns a new instance of HUD.



3
4
5
6
7
# File 'lib/entities/hud.rb', line 3

def initialize(object_pool, tank)
  @object_pool = object_pool
  @tank = tank
  @radar = Radar.new(@object_pool, tank)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



2
3
4
# File 'lib/entities/hud.rb', line 2

def active
  @active
end

Instance Method Details

#drawObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/entities/hud.rb', line 64

def draw
  if @active
    @object_pool.camera.draw_crosshair
  end
  @radar.draw
  offset = 20
  health_image.draw(20, offset, 1000)
  stats_image.draw(20, offset += 30, 1000)
  if fire_rate_image
    fire_rate_image.draw(20, offset += 30, 1000)
  end
  if speed_image
    speed_image.draw(20, offset += 30, 1000)
  end
end

#fire_rate_imageObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/entities/hud.rb', line 36

def fire_rate_image
  if @tank.fire_rate_modifier > 1
    if @fire_rate != @tank.fire_rate_modifier
      @fire_rate = @tank.fire_rate_modifier
      @fire_rate_image = Gosu::Image.from_text(
        $window, "Fire rate: #{@fire_rate.round(2)}X",
        Utils.main_font, 20)
    end
  else
    @fire_rate_image = nil
  end
  @fire_rate_image
end

#health_imageObject



18
19
20
21
22
23
24
25
# File 'lib/entities/hud.rb', line 18

def health_image
  if @health.nil? || @tank.health.health != @health
    @health = @tank.health.health
    @health_image = Gosu::Image.from_text(
      $window, "Health: #{@health}", Utils.main_font, 20)
  end
  @health_image
end

#player=(tank) ⇒ Object



9
10
11
12
# File 'lib/entities/hud.rb', line 9

def player=(tank)
  @tank = tank
  @radar.target = tank
end

#speed_imageObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/entities/hud.rb', line 50

def speed_image
  if @tank.speed_modifier > 1
    if @speed != @tank.speed_modifier
      @speed = @tank.speed_modifier
      @speed_image = Gosu::Image.from_text(
        $window, "Speed: #{@speed.round(2)}X",
        Utils.main_font, 20)
    end
  else
    @speed_image = nil
  end
  @speed_image
end

#stats_imageObject



27
28
29
30
31
32
33
34
# File 'lib/entities/hud.rb', line 27

def stats_image
  stats = @tank.input.stats
  if @stats_image.nil? || stats.changed_at <= Gosu.milliseconds
    @stats_image = Gosu::Image.from_text(
      $window, "Kills: #{stats.kills}", Utils.main_font, 20)
  end
  @stats_image
end

#updateObject



14
15
16
# File 'lib/entities/hud.rb', line 14

def update
  @radar.update
end