
Gosu is a sweet little framework for writing 2D games in Ruby. To quote their wiki:
Gosu aims to contain everything that is necessary to write a game in clean C++ or Ruby code, yet not much more. Our aim is to get the annoying world of hardware and OS interaction out of your way. Think SDL with a very different, less C-ish style.... Everything in Gosu exists for the same single reason: It was necessary for an existing project. Nothing was, and will ever be, added out of boredom.Learning enough about Gosu to write my game was a snap, which meant that in no time I was up and running... into the fact that I haven't thought about math in a looong time. And then there is all that physics stuff. I mean, F=MA is simple, but using it to model a kite on a string is tricky. Even trickier is modelling two kites with strings that interact with one another.
So after a couple days tinkering I don't have a game because in trying to get the kites to interact I ran into all sorts of problems, but I do have kites on a string, and even though I can't get them to fight, they do pal around rather spectacularly. Looping the loop is especially fun and the way the string behaves naturally is fairly entertaining.
The project website is here. Please tinker with the code and add to it. I would love to see how to model the interaction between the strings properly. So hey, if you have read this far you must be interested in some code. The following shows what a basic gosu project looks like. Subclassing the Gosu::Window Class buys the ability to draw to our window, paint images, and access the soundcard. The other main elements to note are the overridden methods update and draw. Update is where you trigger any processing or logic for game interaction. The draw method is where you update the appearance of the objects in the window. It is so simple. Here is the ruby documentation.
require 'rubygems'
require 'gosu'
require 'enumerator'
require 'kite'
class KiteRunner < Gosu::Window
attr_accessor :player1, :player2
def initialize
super(640, 480, false)
self.caption = "Kite Runner Game"
@player1 = Kite.new(self, 300, 470)
@player2 = Kite.new(self, 350, 470)
@background_image = Gosu::Image.new(self, "Sky.png", true)
end
def update
process_keypress
@player1.move
@player2.move
end
def draw
@background_image.draw(0, 0, 0)
@player1.draw
@player2.draw
end
def process_keypress()
close if button_down?(Gosu::Button::KbEscape)
@player1.send('left') if button_down?(Gosu::Button::KbLeft)
@player1.send('right') if button_down?(Gosu::Button::KbRight)
@player1.send('longer') if button_down?(Gosu::Button::KbUp)
@player1.send('shorter') if button_down?(Gosu::Button::KbDown)
@player2.send('left') if button_down?(Gosu::Button::Kb1)
@player2.send('right') if button_down?(Gosu::Button::Kb4)
@player2.send('longer') if button_down?(Gosu::Button::Kb2)
@player2.send('shorter') if button_down?(Gosu::Button::Kb3)
end
end
2 comments:
Gosu is great fun, you can get started so quickly, and it really covers most of what people need to make something fun.
netghost,
Right on! I think that is a testament to the design philosophy of the gosu team. By leaving out the kitchen sink they keep the library flexible and productive.
Post a Comment