Thursday, November 13, 2008

Ruby Pong - Screenshot



The above is a screenshot of the game, Pong, which I discussed in my last post.

Sunday, November 2, 2008

Pong (the game)- Rubygame

I have just finished writing Pong, my first full featured game, in Rubygame.
On top of just the normal Pong action, I have added sound effects and background music.

I have uploaded my source code to my website. Consider the source code "free", i.e. do what you like with it.
You can browse the source code online.

Giving credit where credit is due:
The main tutorial I used to learn how to create Pong was from the "Rubygame Book". It is an excellent starting tutorial. It explains a lot of the initial framework setup.

The background music is from the Rubygame samples. These can be found with the latest release of Rubygame.

The sound effects are from http://freesoundfiles.tintagel.net/Audio/

Questions?
Feel free to ask any questions you may have regarding the source code, or other ruby related issues you may have.

Saturday, November 1, 2008

Rubygame setup

I have just completed my first mock game in rubygame (ruby's version of pygame), and I can't recommend it enough. That said, I did have a few troubles setting it up. The following describes how to setup rubygame in Ubuntu 8.04 (this is likely to work with other recent Ubuntu releases):

1. Download the rubygame gem from the rubygame official site. The gem is currently version 2.3.0.
2. Install any necessary libraries. The README from the rubygame site states that you are required to have:

1. ruby >= 1.8
2. SDL >= 1.2.7
3. rake >= 0.7.0 (for build/install system)

and that you should, but don't have to have:

1. SDL_gfx >= 2.0.10
2. SDL_image >= 1.2.3
3. SDL_mixer >= 1.2.7
4. SDL_ttf >= 2.0.6

I found that I had to have the last 4 SDL libraries to install the rubygame gem.

So, in case you don't already have ruby, rake and gems, the following ruby rails website lists the required commands to install ruby, rake and gems. Note, it will also install rails support, which is a good thing.

To get the required SDL libraries for rubygame, I installed the following packages via apt-get

1. libsdl-ruby1.8
2. libsdl1.2-all
3. libsdl1.2-dev
4. libsdl-gfx1.2-dev
5. libsdl-image1.2-dev
6. libsdl-mixer1.2-dev
7. libsdl-ttf2.0-dev

E.g. sudo apt-get install libsdl-ruby1.8

Once that was complete, I installed the gem. To install the gem, you must be in a terminal at the directory in which the gem is located. You cannot be in another directory, if you are, it won't find the gem.

To install the gem, I did the following:

1. I placed the .gem file I downloaded on my Desktop.
2. I did the following in the terminal to take me to my gem: cd ~/Desktop
3. I did the following in the terminal to install the gem: gem install gem_file.gem

If you did not receive a gem "install failed" message, you are ready to use rubygame. If you did, read the error message, I found that the error message named the libraries I was missing. An example of an error I received was, "could not find file SDL_IMAGE.h". This error meant that I was missing the libsdl-image1.2-dev package.

The following is an example ruby program you can use to test your rubygame install. Note this is the entire file contents. If your ruby install worked, the app will run, opening a window titled "Hello World".


#START FILE

require "rubygems"
require "rubygame"

Rubygame.init

screen = Rubygame::Screen.set_mode [320,240]
screen.title = 'Hello World'
screen.update

queue = Rubygame::EventQueue.new

game_over = false

until game_over do
queue.each do |event|
case event
when Rubygame::ActiveEvent
puts "Hello World. Updating"
screen.update
when Rubygame::QuitEvent
game_over = true
end
end
end

Rubygame.quit

# END FILE