Getting Started With Rubygame
Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. Most people are familiar with Ruby from the Ruby on Rails web framework. There are many other libraries available for Ruby that make it perfect for many other tasks.
Rubygame is a cross-platform game-development library for Ruby, inspired by Pygame. Rubygame is perfect for quick prototypes and rapid development. This tutorial will walk you through the steps involved with getting Rubygame installed on Windows and running your first Rubygame program.
First, we need to install some dependencies. Rubygame obviously requires Ruby. I won't cover installing Ruby, there are plenty of tutorials that cover that topic. The official Ruby Language website is a good place to start. You will also need RubyGems. You can download RubyGems from RubyForge.
All of the other dependencies are parts of the Simple DirectMedia Layer. We aren't going to be compiling anything from source, so we don't need the development libraries, just the run-time libraries. Since all of these libraries are open source, I've bundled them up here in one zip file for you. This file contains DLLs for SDL, SDL_image, SDL_gfx, SDL_mixer, and SDL_ttf.
Download this file and unzip it. It will extract into a folder called SDL. Inside that folder there are 14 DLL files. Copy those DLL files into your Windows\System32 folder.
Now you'll need to download and install Rubygame itself. The latest version as of this writing is 2.1.0. Unfortunately a binary gem for Windows hasn't been made available yet, so we'll download the older version 2.0.1.
After you've saved that file somewhere, open a command prompt, change to that directory, and type the following command:
gem install rubygame-2.0.1-mswin32.gem
This will copy the Rubygame files to your gems directory and install the documentation. There are a few sample applications included with Rubygame.
Hello World In Rubygame
Now that we have Rubygame installed, let's make sure it's working. The program below is probably the simplest example of Rubygame. It initializes the library, creates a 320x240 blue screen, and runs an event loop until you click the close button.
#!/usr/bin/env ruby require 'rubygame' Rubygame.init screen = Rubygame::Screen.set_mode [320,240] screen.title = 'Hello World' screen.fill [0,0,255] screen.update queue = Rubygame::EventQueue.new game_over = false until game_over do queue.each do |event| case event when Rubygame::ActiveEvent screen.update when Rubygame::QuitEvent game_over = true end end end Rubygame.quit
Type this into a new file in your favorite editor and save it as hello.rb. You can then run it from the command line like this:
This should get you started with Rubygame. See my other tutorials for more information about SDL.