Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/game_2d/message.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #draw ⇒ Object
- #drawn? ⇒ Boolean
-
#initialize(window, font, lines) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(window, font, lines) ⇒ Message
Returns a new instance of Message.
5 6 7 8 9 10 |
# File 'lib/game_2d/message.rb', line 5 def initialize(window, font, lines) @window, @font, @lines = window, font, lines @fg_color, @bg_color = Gosu::Color::YELLOW, Gosu::Color::BLACK @drawn = false end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
12 13 14 |
# File 'lib/game_2d/message.rb', line 12 def lines @lines end |
Instance Method Details
#draw ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/game_2d/message.rb', line 17 def draw count = @lines.size line_height = @font.height lines_height = line_height * count lines_top = (@window.height - (count * line_height)) / 2 x_center = @window.width / 2 @lines.each_with_index do |line, n| @font.draw_rel(line, x_center, lines_top + (line_height * n), ZOrder::Text, 0.5, 0.0, 1.0, 1.0, @fg_color) end max_width = @lines.collect {|line| @font.text_width(line)}.max lines_bottom = lines_top + (line_height * count) left = x_center - (max_width / 2) right = x_center + (max_width / 2) @window.draw_box_at(left - 1, lines_top - 1, right + 1, lines_bottom + 1, @fg_color) @window.draw_box_at(left, lines_top, right, lines_bottom, @bg_color) @drawn = true end |
#drawn? ⇒ Boolean
36 |
# File 'lib/game_2d/message.rb', line 36 def drawn?; @drawn; end |