class HUD

Attributes

active[RW]

Public Class Methods

new(object_pool, tank) click to toggle source
# 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

Public Instance Methods

draw() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/entities/hud.rb, line 9
def player=(tank)
  @tank = tank
  @radar.target = tank
end
speed_image() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/entities/hud.rb, line 14
def update
  @radar.update
end