Class: Message

Inherits:
Object
  • Object
show all
Defined in:
lib/game_2d/message.rb

Direct Known Subclasses

PasswordDialog

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#linesObject

Returns the value of attribute lines.



12
13
14
# File 'lib/game_2d/message.rb', line 12

def lines
  @lines
end

Instance Method Details

#drawObject



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

Returns:

  • (Boolean)


36
# File 'lib/game_2d/message.rb', line 36

def drawn?; @drawn; end