Hello Gosu!

Posted by Joe Yates Sat, 19 Feb 2011 13:09:00 GMT

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 a window:
Hello Gosu!

The complete code is in a GitHub repository.