Class: HUD
- Inherits:
-
Object
- Object
- HUD
- Defined in:
- lib/entities/hud.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
Instance Method Summary collapse
- #draw ⇒ Object
- #fire_rate_image ⇒ Object
- #health_image ⇒ Object
-
#initialize(object_pool, tank) ⇒ HUD
constructor
A new instance of HUD.
- #player=(tank) ⇒ Object
- #speed_image ⇒ Object
- #stats_image ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
2 3 4 |
# File 'lib/entities/hud.rb', line 2 def active @active end |
Instance Method Details
#draw ⇒ Object
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_image ⇒ Object
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_image ⇒ Object
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_image ⇒ Object
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_image ⇒ Object
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 |
#update ⇒ Object
14 15 16 |
# File 'lib/entities/hud.rb', line 14 def update @radar.update end |