Hello Gosu!

2011/2/19

Hello Gosu!

I'm trying out Gosu, which is a 2D game library written in C++ with Ruby bindings (Wikipedia article).

The Ruby documentation is sparse but sufficient.

The gem is easy to install:

$ gem install gosu

A 'Hello World!' app requires about 20 lines of code:

require 'rubygems'
require 'gosu'

class HelloWindow < Gosu::Window
  def initialize
    super( 250, 100, false )
    @background_image = Gosu::Image.new(self, 'hello_world.png')
  end

  def draw
    @background_image.draw(0, 0, 1)
  end

  def button_down(id)
    close
  end
end

HelloWindow.new.show

Run it like this:

$ ruby hello_gosu.rb

The program creates the window shown at the start of this article.

The complete code is in a GitHub repository.