Class: ScoreDisplay
- Inherits:
-
Object
- Object
- ScoreDisplay
- Defined in:
- lib/entities/score_display.rb
Instance Method Summary collapse
- #create_stats_image(stats) ⇒ Object
- #draw ⇒ Object
- #draw_top_right ⇒ Object
-
#initialize(object_pool, font_size = 30) ⇒ ScoreDisplay
constructor
A new instance of ScoreDisplay.
Constructor Details
#initialize(object_pool, font_size = 30) ⇒ ScoreDisplay
Returns a new instance of ScoreDisplay.
2 3 4 5 6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#create_stats_image(stats) ⇒ Object
14 15 16 17 18 19 20 |
# 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 ⇒ Object
22 23 24 25 26 27 |
# 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 ⇒ Object
29 30 31 32 33 34 |
# File 'lib/entities/score_display.rb', line 29 def draw_top_right @stats_image.draw( $window.width - @stats_image.width - 20, 20, 1000) end |