2008-07-28

My entry for the Rubygame Weekend Contest #2: a roguelike in Scheme

Joining the contest was a lot of fun, and I highly recommend these weekend events to anyone who wants to learn how to write games. With the trick of a short time span to motivate yourself and lots of experienced guys on IRC focused in much the same tasks as you, this was more educative than months of reading tutorials.

The theme was “opposites”, and I’m interested in simulations, so my game idea was of an alien world with two complementary species. When pranjos die they create plants that are the source of food for bluos, and vice-versa. But these animals are not very adept at surviving, and their populations are threatened: oranjos are lazy and don’t explore much, so they starve to death without finding food; and bluos are timid and breed too seldom. As a space biologist, it’s your task to throw oranjos and bluos around to increase their numbers.

At least that was the idea.

[feed readers: continue to postmortem and screenshots…]

Structured procrastination rules

For some reason, working in this game made me very motivated to act on another idea I had for ages: a console roguelike using Japanese kanji and other Unicode characters. I made a few attempts at writing games in the past, but all came to naught. It’s hard to admit, but looking back, I think I simply lacked the experience and knowledge to finish one. I had no idea of how to write the essential basics, like how to model game objects and the world and where exactly to put their attributes and methods (should an object’s position be stored in the object itself, or in the world object? Who handles collision detection? Sight? Viewport scrolling reactions to object-induced events?). My math and geometry skills are rusty, and you need them like ALL THE TIME — even in 2D or console games — for such basic tasks as collision detection, proximity, line of sight, and so on. Trying to write games without paying enough attention to these topics confused me, and I’d interpret that feeling as “laziness” and stop coding.

So getting Maggaworld to do something was amazing, even if the “something” I did is only a bunch of oranjos walking over a single screen, getting older, breeding, and starving to death (which would be much more interesting had I draw more than three frames of animation). I didn’t make no plants, no bluos, no player, no real world with scrolling and uneven terrain. I actually only worked in Friday night and through the Saturday afternoon; then I got an irresistible urge to hack Makai・Jukai (the roguelike) — which I did in perfect flow until some ~800 lines of scheme mid-Monday, when I grudgingly teared myself away from home to, you know, work.

screenshot of early maggaworld

Maggaworld postmortem and links

The most costly decision was to use Chipmunk, that amazing 2D physics simulation library which IMHO indie developers don’t pay enough attention to. The demos are so cool, and I though I’d avoid calculating collision detection and gravity, but boy what a price to pay. 80% of the time I spent with Maggaworld wasn’t on the game itself, it was getting my head around the most basic principles of Chipmunk — it’s way too powerful for what I had in mind. In fact, I often had to learn concepts only to disable them, like setting the angular momentum of bodies to infinity to prevent rotation. In my first few attempts, I made the Shape definitions all wrong and the oranjos would just fall through the floor =D I ended up coding a falling squares demo to teach myself, and only then managed to get Maggaworld working. I documented the demo and hope it’ll be useful for other Gosu + Chipmunk users. If you’re also new to game coding and want to use Chipmunk in a weekend contest, I suggest writing some demos yourself before the start!

screenshot of falling squares ruby+chipmunk demo

If Chipmunk’s complex (by necessity), Gosu is a pleasure. It’s a very ruby-like, convenient high-level library that makes sense; it’s how I wished SDL was when I first tried it. A shame neither Gosu nor Chipmunk are packaged in Debian yet (or in rubygems, for that matter).

Writing games is a lot of work! I seriously overestimated how much I could chew; the art alone took several hours (yes, those three 32×32 childlike sprites took all that time!). I stated that my goal with the contest was not winning but finishing something; at the end of the weekend I failed, but in another sense it was a big personal success — my ideas for how to code Makai・Jukai are coming to reality nicely, and I haven’t given up Maggaworld either (though I’ll probably add the missing elements at a leisure pace). I even forced myself to come out of the closet this time: there’s a rubyforge page for Maggaworld now, and a git repository for Makai・Jukai is available in my site at http://namakajiri.net/code/git/makai. I welcome input from anyone interested, and thanks all the people who kept up with my questions in freenode =D I’m totally joining the next contest!

screenshot of early makaijukai

3 comments

  1. nice writeup.. I love the chipmunk demo, i HAVE to get into that soon :).

    btw, the oranjos are megacute ;D

    Comment by ippa2008-07-29 21:14:00

  2. thanks ippa! today I managed to get them to scale with age when they’re young — including chipmunk’s collision detection shapes :)

    Comment by leoboiko2008-07-30 23:52:35

  3. maggaworld screenshot, 2008-08-01

    Now with scaled collision detection shapes!

    Comment by leoboiko2008-08-01 12:19:58

Leave a comment