class ScoreDisplay

Public Class Methods

new(object_pool, font_size=30) click to toggle source
# File lib/entities/score_display.rb, line 2
def initialize(object_pool, font_size=30)
  @font_size = font_size
  tanks = object_pool.objects.select do |o|
    o.class == Tank
  end
  stats = tanks.map(&:input).map(&:stats)
  stats.sort! do |stat1, stat2|
    stat2.kills <=> stat1.kills
  end
  create_stats_image(stats)
end

Public Instance Methods

create_stats_image(stats) click to toggle source
# File lib/entities/score_display.rb, line 14
def create_stats_image(stats)
  text = stats.map do |stat|
    "#{stat.kills}: #{stat.name} "
  end.join("\n")
  @stats_image = Gosu::Image.from_text(
    $window, text, Utils.main_font, @font_size)
end
draw() click to toggle source
# File lib/entities/score_display.rb, line 22
def draw
  @stats_image.draw(
    $window.width / 2 - @stats_image.width / 2,
    $window.height / 4 + 30,
    1000)
end
draw_top_right() click to toggle source
# File lib/entities/score_display.rb, line 29
def draw_top_right
  @stats_image.draw(
    $window.width - @stats_image.width - 20,
    20,
    1000)
end