class LifeGameWindow

Keybinds: s - Start and stop (pause) the game c - Clear the grid r - Randomize the grid Left Click - Invert the state of the cell clicked q/Esc - Quit

Public Class Methods

new() click to toggle source

Initialize Gosu window and LifeGrid

Calls superclass method
# File lib/NanoLife.rb, line 23
def initialize
  # Gosu window
  super WIN_WIDTH, WIN_HEIGHT, false, 1000.0 / MAX_FPS
  self.caption = 'NanoLife - Conway\'s Game of Life'
  # Create a game of life grid and start randomly
  @grid = LifeGrid.new(self)
  @grid.randomize
  # Set running to true. Game can be paused with keyboard
  @running = true
end

Public Instance Methods

button_down(id) click to toggle source

Override callback for a button pressed

# File lib/NanoLife.rb, line 50
def button_down(id)
  if id == Gosu::KbEscape or id  == Gosu::KbQ
    close
  elsif id == Gosu::KbS
    @running = !@running
  elsif id == Gosu::KbC
    @grid.clear
  elsif id == Gosu::KbR
      @grid.randomize
  elsif id == Gosu::MsLeft
    @grid.invert_cell(
      mouse_x.to_i / CELL_SIZE,
      mouse_y.to_i / CELL_SIZE
    )
  end
end
draw() click to toggle source

Draw screen

# File lib/NanoLife.rb, line 45
def draw
  @grid.draw
end
needs_cursor?() click to toggle source

Turn on cursor

# File lib/NanoLife.rb, line 35
def needs_cursor?; true; end
update() click to toggle source

Update everything each frame before drawing

# File lib/NanoLife.rb, line 38
def update
  if @running # and delta is met
    @grid.update
  end
end