Procedural Land Creation with JRuby, Slick2D and Perlin Noise

For something different, I decided I would try my hand at doing some game development programming. I was incredibly inspired by many of the indie games I watch being actively developed, and I figured it would be a interesting way to learn some brand new things totally outside of my usual purview.

I wanted to do some more work with JRuby, as I had a good hack with it at work, but haven't touched it in a while, so I hunted down which framework for doing a game. I've decided I wanted to do a desktop based 2D something (no idea what still), so settled on Slick2D as my framework of choice.

I've starting leaning towards doing something open world-ish, which meant I needed to generate out a large chunk of landscape without having to hand build a map, and yet also make sure it was the same every time a user came back to a particular world. That lead me to start investigating Perlin Noise, and I settled on the perlin_noise ruby library for generating that, and so far it's been very good.

It's been interesting too, having JRuby as the platform. It's a tough choice deciding whether to use a Java library or a Ruby one. With Slick2D it was easy – it was the best there was, and it hooks straight into OpenGL. With something like a Perlin Noise library, ease of use was the primary concern, and managing gems with Bundler and having a direct line to a nice Ruby syntax based API was the deal clincher. Although if it ever becomes a performance concern, I may look to go back to straight Java.

So here is a video of what I have so far. It's still very raw, but basically it's a circular big world, that if you go one way for long enough, you come back right where you started.

 

I'm extending Slick2D's Shape class to create my world object (basically a circle that I modify with my generated perlin noise). I've already set it up so the world has a "coordinate", and that controls what the world looks like. In theory, if this ever becomes a real game, you could give someone else your world coordinates and they would see the same world you do.

Before anyone asks, I've not decided what this is going to be, or if I'll open source it, or what (it's a bit of a sandpit at the moment), but I'll keep writing a diary here of what I've been doing with it, with appropriate links as long as it keeps staying interesting.

Got a few ideas on where to go next (zoom in and out, dynamic texturing of the landscape, etc), but haven't committed yet. This stuff is pretty interesting, and very different from the sort of stuff I code on a day to day basis.

Let me know if you find this interesting, and I'll keep writing about it!

Leave a Comment