Class: RbSnake::Views::Window
- Inherits:
-
Object
- Object
- RbSnake::Views::Window
- Defined in:
- lib/rb_snake/views/window.rb
Constant Summary collapse
- PIXEL_SIZE =
50
Instance Method Summary collapse
-
#initialize ⇒ Window
constructor
A new instance of Window.
- #render(state) ⇒ Object
- #start(state) ⇒ Object
Constructor Details
#initialize ⇒ Window
Returns a new instance of Window.
13 14 15 |
# File 'lib/rb_snake/views/window.rb', line 13 def initialize @ruby2d_window = Ruby2D::Window.new end |
Instance Method Details
#render(state) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/rb_snake/views/window.rb', line 25 def render(state) state.food.render(ruby2d_window) do |row, col| render_square(row: row, col: col, color: "yellow") end state.snake.render(ruby2d_window) do |row, col| render_square(row: row, col: col, color: "green") end end |
#start(state) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rb_snake/views/window.rb', line 17 def start(state) setup_window(state.grid) add_key_listener(state) render_on_each_frame(state) ruby2d_window.show end |