class Message

Attributes

lines[R]

Public Class Methods

new(window, font, lines) click to toggle source
# 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

Public Instance Methods

draw() click to toggle source
# 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?() click to toggle source
# File lib/game_2d/message.rb, line 36
def drawn?; @drawn; end
lines=(new_lines) click to toggle source
# File lib/game_2d/message.rb, line 13
def lines=(new_lines)
  @lines, @drawn = new_lines, false
end