It rained yesterday afternoon, and I had the chance to observe raindrops descend from the edge of a roof while I gave an exam to some of my math students. While doing so, I thought that the effect that it gave might look good as a starfield in a space shooter. And so, we have this “starfield rain” demo:
starfield rain
Three things would probably make this implementation different from your usual starfield:

  1. The stars’ movement is influenced by constant acceleration, not by constant velocity (much like raindrops against gravity).
  2. This isn’t a parallax starfield, meaning, we do not have more than two layers of starfields with differing velocities. The fact that the velocity of each star changes at each frame should make up for this – a large number of velocities may be observed at any given time.
  3. The stars have trails, much like heavy raindrops. I think the trails add a nice touch.

I was able to write out this code in a little less than a couple of hours, and I am certain that someone with more programming experience would probably be able to produce something like this, or something of even better quality, in a few minutes.

I think that mini-coding exercises like this are a good thing for beginners – you don’t immediately go for Everest; instead, you gain experience by climbing a a lot of other mountains first.

The code (requires Python and Pygame to run) should be easy to understand, but I wasn’t able to add comments to it. I will probably discuss how it works in a future post.

But of course, in keeping with the spirit of the exercise, I encourage you to try to implement this on your own. Starting small should be helpful in managing bigger game programming projects later on.

I think we have the beginnings of a Pygame particle system here :).