5/12/09:We won the CodeProject "World's Fastest Server" competition for our entry using Rails and Google StreetView. Thanks to all involved, we enjoyed participating!
4/3/09: We've updated our design using the new 960 CSS framework, cufón, and the Ruby DSL Sass
_why has a new project floating around in github called bloopsaphone. It’s a cool little ruby library that interfaces with portaudio to let you easily create 8-bit audio sound effects and music
I decided to kick the tires on bloopsaphone by integrating it into a simple game using Shoes, another awesome _why project. Bloopsaphone appears destined to make a showing in the next version of Shoes, “Policeman”, which is also featuring ruby 1.9 and other improvements, but I couldn’t get the development builds running on my Mac yet, so I decided to try my luck with Shoes 2
This is a classic pong game, with code based off the sample in the shoes repo. I switched the game to be played left/right instead of top/bottom, did a little refactoring, and added the ability to pause the game and score points
Here’s a video to whet your appetite (it’s a little choppy, a result of the capture software recording less FPS than the game plays at):
Bloops and Shoes
I had problems getting Bloops and Shoes to play nice with each other. It seems related to the fact that Bloops likes to have some time to itself to play the audio – all the tutorials I found used code like this to play the audio(after setting up the tune):
sounds.play
sleep 1while!sounds.stopped?
The problem was I couldn’t just pause the game for a second to play the sound effects. If I removed the sleep command, Shoes would crash the first time it tried to play a sound. I could tweak the sleep command to use a shorter duration, but this would still occasionally lead to the game visibly stuttering
The eventual solution I came upon was to play the audio in a new thread like this:
The code starts a new thread, adds the appropriate sound effect and note as a tune to the Bloop object, plays the sound and sleeps until it’s done, and then clears that tune off the object (by default new tunes gets added on top of existing ones)
I haven’t spent any time prettying up the code, but if you’d like to grab it in all it’s messy glory, it’s available on github
Try it yourself
To get this running on Mac OS X 10.5 with MacPorts, follow these steps:
sudo port install portaudio
cd ~/Desktop
git clone git://github.com/why/bloopsaphone.git
cd bloopsaphone
make ruby
cd ..
That will install portaudio from MacPorts, clone the bloops repo and build it, clone our ruby_pong repo, and copy the compiled ruby/bloops bindings into the ruby_pong directory
At that point you should be able to grab the current version of Shoes and drag the file pong.rb file from the ruby_pong directory onto the Shoes app to play pong. Spacebar pauses the game and the score goes to 7. The source, while not well factored, should be relatively easy to read, so go ahead and open up pong.rb to tweak the game parameters (e.g. size of the board, computer speed, winning score) or pong_sounds.rb to change the sound effects for a bounce, hit or score
Shoes and Bloopsaphone are a lot of fun, but still a bit rough around the edges. Don’t get discouraged if you run into some problems testing them out