Class: KameWindow
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- KameWindow
- Defined in:
- lib/kame/kame_window.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #draw_background ⇒ Object
- #grid ⇒ Object
-
#initialize(lines, options) ⇒ KameWindow
constructor
A new instance of KameWindow.
- #update ⇒ Object
Constructor Details
#initialize(lines, options) ⇒ KameWindow
Returns a new instance of KameWindow.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kame/kame_window.rb', line 4 def initialize(lines, ) @width = [:width] @height = [:height] @background_colour = Gosu::Color.argb(KameColours::lookup[[:paper]]) @speed = [:speed] @grid = [:grid] @grid_size = [:grid_size] @grid_colour = Gosu::Color.argb(KameColours::lookup[[:grid_colour]]) @lines = lines @first_frame = Gosu::milliseconds super(@width, @height, false) self. = [:title] end |
Instance Method Details
#draw ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kame/kame_window.rb', line 47 def draw self.draw_background self.grid if @grid return if @lines.nil? || @lines.count == 0 || @seconds_since_last_frame.nil? max = (@seconds_since_last_frame * @speed).round if max > @lines.count - 1 max = @lines.count - 1 end 0.upto(max).each do |i| line = @lines[i] line_colour = Gosu::Color.argb(line[:colour]) draw_line(line[:from][:x], line[:from][:y], line_colour, line[:to][:x], line[:to][:y], line_colour, 10) end end |
#draw_background ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/kame/kame_window.rb', line 19 def draw_background draw_quad(0, 0, @background_colour, @width, 0, @background_colour, 0, @height, @background_colour, @width, @height, @background_colour, 0) end |
#grid ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kame/kame_window.rb', line 27 def grid @grid_font ||= Gosu::Font.new(self, "Arial", 10) @grid_size.times do |i| c = (@width / @grid_size) * (i + 1) r = (@height / @grid_size) * (i + 1) draw_line(0, r, @grid_colour, @width, r, @grid_colour, 1) @grid_font.draw(r.to_s, 2, r - 11, 1, 1, 1, @grid_colour) draw_line(c, 0, @grid_colour, c, @height, @grid_colour, 1) c_width = @grid_font.text_width(c.to_s) @grid_font.draw(c.to_s, c - c_width - 2, @height - 13, 1, 1, 1, @grid_colour) end end |
#update ⇒ Object
42 43 44 45 |
# File 'lib/kame/kame_window.rb', line 42 def update @this_frame = Gosu::milliseconds @seconds_since_last_frame = (@this_frame - @first_frame) / 1000.0 end |