Droplet

Screenshot

I’m pleased to present my entry to the RubyWeekend #3 game competition: Droplet. From the README:

Droplet is a small musical toy created by John Croisant in 72 hours over the weekend of June 26-28, 2009 for the third RubyWeekend game creation competition.

The theme of the competition was “A Tiny World”. The inspiration for Droplet comes from photographs that people have commonly described as “tiny worlds”: droplets of water, and the small plants and fungi that grow underfoot.

Initially, Droplet was going to feature both plants and creatures interacting in their tiny droplet world, but I abandoned plans for the creatures due to time constraints. So, what’s left is abstract, rainbow colored plants that sing when you tickle them!

Enjoy!

The controls are simple:

  • Left click anywhere on the edge of the droplet (the large circle) to plant a seed. The seed will gradually grow into a tree-like plant of a random color.
  • Move the mouse cursor around near a grown plant to tickle it and make it sing. The faster and longer you tickle, the louder it sings. The sound each plant produces is randomly chosen from the “data/sounds/” directory.
  • Right click the trunk of a plant to remove it.
  • Click “Help / Credits” to view controls help and game credits.
  • Press Escape to quit the game.

To run Droplet, you will need Ruby 1.8.6 (1.9 might work), Rubygame 2.5.2 (with SDL_gfx, SDL_image, and SDL_mixer support), and Gamebox 0.0.4.

Posted in Projects, Ruby, RubyWeekend | Leave a comment

Droplet – End of Day 3

Screenshot

What’s working:

  • Plants have a limited number of generations, so they don’t start to slow everything down.
  • Plant colors, branch length, and various other attributes are randomized per plant for more variety.
  • You can rustle the plants by moving your mouse cursor around them. This makes them wave back and forth for a while, and will eventually make them “sing” louder.
  • I made a custom method for drawing branches, which is a bit faster than draw_line_s, and anti-aliased, but not as roundy at the ends.

What’s not:

  • The algorithm for calculating how much you rustled a plant is a bit dodgy.
  • Still no sound. I’m definitely adding that tomorrow, though. I’ve got a few chime sound loops prepared, and I’ll make some wind/pad loops too.
  • I decided not to use Garage Band due to time constraints and because I wasn’t sure about licensing (since I’d just be making short samples). I’m using some nice chimes and pads from freesound.org instead.
  • I need to a title and instructions and credits in the side bar.
  • Maybe add a way to kill plants that you don’t want anymore?

All in all, though, it’s coming together well. 16 hours left.

Posted in Projects, Ruby, RubyWeekend | 1 Comment

Droplet – End of Day 2

A quickie progress update and screenshot of my RubyWeekend game, Droplet.

Screenshot

What’s working:

  • You can click to make a new plant at the nearest point on the circle.
  • The plants grow a bit when you press spacebar.
  • The plants grow and create new branches based on rules.

What’s not:

  • The plants are ignoring their color rules.
  • The plants are “leaning”.
  • The plants are jaggy and slow to draw (when complex). I’ll probably have to stop using Gamebox’s “thick line” method (draw_line_s), and either use regular lines (maybe antialiased) or roll my own code to draw branches. OpenGL would be really nice right now…
  • The plant rules are a bit simplistic and rigid.
  • No sound yet.

The contest period is nearly half over (39:30 hours left as of this writing). I’m going to try to fix the color and leaning issues, then head to bed. The focus tomorrow will be on sound/music.

Update 03:52: Fixed the color and leaning issues. Both were just stupid little mistakes. Here’s an updated screenshot:

Screenshot

Posted in Projects, Ruby, RubyWeekend | Leave a comment

Droplet Thoughts (Day 2)

I’m calling my RubyWeekend #3 game “Droplet”. I will not proceed to ramble about it to help my planning. And you get to read the results, you lucky person you!

  • I’m setting aside the animals/people aspect for the competition. It’s just going to be about the plants.
  • I’m going to use Garage Band’s built-in instruments to create the music sound effects for the game. I am in love with Garage Band.
  • I’ll be using Gamebox. It seems pretty cool so far.
  • Since the game takes place on the inside surface of a circle, I’ll need to do some trigonometry to calculate the positions and angles of plants around that circle. After a bit of thought on this, I’ve decided I’ll make a PivotActor that represents the center of the circle and contains the math code to calculate the positions of plants given an angle, and also calculate the point on the circle nearest to the mouse cursor.

I’ll update this post with more thoughts as I have them.

Posted in Projects, Ruby, RubyWeekend | Leave a comment

RubyWeekend #3 Game Concept

RubyWeekend #3 kicked off about 8 hours ago, and I’ve been pondering game ideas since then. The theme is “A Tiny World”. I was having trouble coming up with something, but I think I’ve finally got a solid base for a game. It’s still a bit vague, and I haven’t figured out how I’ll turn it into a proper game, with an objective and challenge and such. Right now it’s just kind of a neat idea for a toy. (Which, to be honest, I find more interesting to create, but I should at least try to make it somewhat game-ish for the competition.)

Read More »

Posted in Projects, RubyWeekend | 1 Comment

99% Pure Functional Programming

In my recent adventures in Haskell and Scheme, I was immersed in the concept of functional programming. Haskell in particular has a strong relation with the notion of pure functions, i.e. functions without side effects. A pure function does nothing except calculate and return some value based on the input parameters.

I like pure functions, and I try to write them where I can. But Haskell is billed as a “purely functional programming language”. This perplexed me. How could there be an entire programming language that was purely functional? Or, rather, how could you use such a language to actually do anything useful?

Consider this: if you’re restricting yourself to absolutely no side effects, you’re not allowed to write to files, send data over a network, print text to the console, draw images on the screen, or anything like that. (So much for any ideas of writing a game in a purely functional language!) A program with no side effects is a sort of black hole: parameters can go in, but nothing comes out (except the program exit status code, which is the “return value” of the program). The user doesn’t see anything, no files are changed, no packets sent over the network. The program leaves behind no legacy: the system is in much the same state after the program has run as it was before the program ran.

And yet, at least one useful bit of software has been written in Haskell: the darcs revision control system. So what’s the secret? How did they do it?

Well, it’s simple: Haskell isn’t entirely pure. It’s “tainted” with some functions that do have side effects, such as writing to files and printing text.

Granted, it’s noteworthy that Haskell can get by without many other common side effects, like editing strings or lists in-place, modifying object state, or keeping global variables. It does force you to think in a functional way, and to break many bad habits. And striving for functional programming, regardless of the language you are using, often results in cleaner, less buggy, and easier to maintain code.

But at the end of the day, if you want to accomplish anything, you have to make some concessions to imperative programming. There has to be a side effect somewhere.

Posted in Misc | 1 Comment

Fun (and not-so-fun) with Haskell and Scheme

Lately I’ve been poking around at some new-to-me programming languages, Haskell and Scheme. I don’t expect to use either of them in a serious, practal project (except maybe Scheme for scripting GIMP), but they are both “weird” enough that it’s fun to learn them and expand my horizons.

For Haskell, I’ve been following along with the brilliant and funny Learn You a Haskel for Great Good. It’s in a similar spirit to Why’s (Poignant) Guide to Ruby, but more instructive and less nonsensical, without being any less funny. In addition to being a highly readable and excellent learning resource, it’s also home to golden quotes like this:

You also can’t set a variable to something and then set it to something else later. If you say that a is 5, you can’t say it’s something else later because you just said it was 5. What are you, some kind of liar?

And totally irrelevant but highly amusing illustrations like this:

A cartoon octopus playing Guitar Hero

I therefore assert that Learn You a Haskell is the most awesome guide to any programming language, ever.

Even with a great guide, though, Haskell is a lot to wrap your head around. Partly because of its functional nature, and partly because of its outlandish concepts like curried functions, partial application, and folding, Haskell busted my brain halfway through chapter 6. (Okay, in my defense, it was also 4 AM.)

But it seems like a really interesting language once you grasp it, so I plan to revisit it later.

I also dabbled in Scheme a little bit, following Teach Yourself Scheme in Fixnum Days. Unfortunately, Teach Yourself Scheme isn’t nearly as entertaining or thorough as Learn You a Haskell. It’s very dry reading, and unless analyzing macro expansions gets you off, you probably won’t find it too enjoyable.

But, I was already familiar with Lisp, so most of the concepts weren’t terribly foreign, and I didn’t need as much handholding. For the most part, I just needed an introduction to the terms and function syntaxes peculiar to Scheme. But therein lies a problem: there are lots of Scheme implementations, and they are all peculiar.

SchemeWiki.org lists some 70 different implementations of Scheme, and none of them are authoritative. Perhaps in an attempt to remain apolitical, very few of the lists I’ve found give any sort of indication of which ones are any good. Which are stable, efficient, easy to install and use? Which ones have the most users? What features do they support? Are they still actively developed? Which (if any) of the 6 or 7 Scheme standards are they compliant with? What quirks or extra behavior do they have?

Am I expected to download and try every implementation, devise tests and benchmarks to determine compliance, efficiency, and feature set, and then decide which one I want to use to learn the language? Not gonna happen. Even reading the web sites for every implementation is more effort than I’m willing to spend. If there were 2 or 3 to choose from, sure, but not 70.

In the end, I just said “screw it” and installed Gambit on the highly scientific basis that it has a cool name. But, I might use MzScheme for learning, since that’s what Teach Yourself Scheme uses, and I wouldn’t know the difference.

I’m still interested in learning more Scheme (at least enough to find out what’s so great about call/cc), but the learning experience so far has not been nearly as rewarding or entertaining as it has been with Haskell.

Maybe Scheme needs a tutorial with a sense of humor and an octopus playing Guitar Hero?

It couldn’t hurt.

Posted in Misc | Tagged , | Leave a comment

Solunaria

Here’s my entry for RubyWeekend #2: Opposites. You can read my progress logs in the rubyweekend section if you’re interested in reading about how I got the idea and the process involved in making the game.

In Solunaria, you control a giant, glowing, magical moth. It’s your job to round up the smaller moths, but there’s a problem: the smaller moths come in two varieties: solar moths (orange) and lunar moths (blue), and they’ll only follow something of the same color as them!

Fortunately, since you’re a magical moth, you can change color (left click) to attract each color of moth. The catch is that there are also colored glowbugs flying around, and the small moths have a tendency to follow the glowbugs if they get too close. Silly moths!

Solunaria Screenshot Thumbnail

Download the game! (Requires Rubygame 2.3.)

I didn’t completely finish the game (there’s no winning or losing conditions), but it’s still kinda fun to fly around and guide the moths. And it was a lot of fun to make the game in the first place!

Be sure to check out the other entries to the RubyWeekend #2 contest. There will be voting starting tomorrow, so check the contest forum then.

Also tomorrow, I’ll write up a post-mortem about making the game, just like I did for the previous contest.

Posted in RubyWeekend | Tagged , , , | Leave a comment

More Screenshots

LilMoths attracted to glowbugs:

LilMoths attracted to glowbugs

LilMoths displaying color preference:

LilMoths displaying color preference

Posted in RubyWeekend | Leave a comment

New Solunaria Screenshot

Here’s a crappy JPEG screenshot of the current progress of my game.

Screenshot with small moths and background

As you can see, I’ve added smaller moths of different colors. The small moths follow the big moth, although if there was anything else around they’d follow it if they got too close. Next I’m going to make them act differently based on their color compared to your color.

I’ve also added a starfield background image which I threw together in 5 minutes in the GIMP.

(2:30 hours left!)

Posted in RubyWeekend | Leave a comment