Tuesday, August 17, 2010

Gnibbles

For most of the past week, I have been working intensively on a Java program -- more specifically, a clone of Gnibbles (a snake game officially known as GNOME Nibbles).

I'm not close to being finished yet, but the game is basically functional. Here is a screenshot with two players (at the moment there can be up to four):

Gnibbles Game

The green triangle is a "frog", which is eaten to gain points (and to grow longer). The dark grey triangle is a bonus, which currently has the same effect as the frog when eaten, but which will in later versions come in various colours and shapes, and have more interesting effects (like gaining a life, temporarily slowing down, getting shorter, teleporting, shedding skin, and so on).

The right part of the screen shows the players' scores and how many lives they have left (each life being represented by a circle). At the moment, the only serious bug is that the players' lives don't update properly. Well, behind the scenes they do, but the number of circles displayed on the screen is always the same.

The main gap in functionality is that there are no impermeable walls. In fact, there aren't really any walls at all. The outer boundaries only serve as teleporters to keep the snakes in the playing field. When, for example, the head of a snake goes past the right boundary, it pops up at the left boundary (i.e. the playing field wraps around).

In the Game menu, when one clicks on "Options", the following window pops up:

Gnibbles Options

At the moment, there is only one level, so the level-related options have no effect. Everything else works, though; it is possible to adjust the number of players, the players' colours, the keys used to move around, and the speed. Other settings (maximum number of players, possible speeds, initial positions, and so on) can be changed with more or less ease by changing the code.

Anyway, speaking of the keys used to move around, they can be changed by clicking on the "Controls" button beside each player's colour in the "Options" window. The following window pops up:

Gnibbles Controls

As you can see, there are four squares at the top, each representing a direction of movement. The selected direction is highlighted. One presses the desired key for that direction, then selects another direction (by clicking on the square or pressing TAB), presses the desired key for that direction, and so on. Some keys, like TAB, ALT, and SPACE, aren't allowed, because they have other functions.

Well, that's the gist of the game. As a programming project, I suppose it's shamefully elementary for an Informatik student about to begin her fifth semester, but I find it fun and worthwhile, and much easier now than it was the first time I attempted to make my own version of Gnibbles (maybe a year or two ago).

For the next while, I'll probably be concentrating on fixing the abovementioned bug, writing Javadoc comments, and increasing the elegance, consistency, and flexibility of what I've already written. The latter two activities (writing comments and refactoring) are actually surprisingly interesting and rewarding, but they do slow the momentum of the project down considerably. It would be unjust to liken refactoring to a bog, because (as I said) it's not unpleasant, but one does risk getting so caught up in tweaking the code that the actual functionality of the program never advances beyond a certain point.

By the way, one last (lengthy) remark: I have been using Eclipse for the project, and have finally begun exploring some of the many handy features. I have really only scratched the surface, but even having things like bookmarks and tasks (and arranging the workspace and views to my taste) makes the experience much pleasanter.

One especially useful feature that I don't make nearly enough use of is the debugger. Somehow I've never properly caught on to debuggers in general, even though they're much better than my usual approach of inserting print commands at select locations in the code. But I hope to change all that (and by "that", I mean doing it the stupid way (o: ).

Tuesday, August 03, 2010

A Tribute to Owls

Unlike, for example, quiche and mackerels, I have never eaten an owl. In fact, I have not had much experience of any kind with them. I did go owl watching once in grade 9 (I was a member of the "Environment Club" at the time), and my sister and I spotted an owl outside our dorm at UBC. Other than that, though, I've seen owls only in pictures (moving and otherwise) and in the form of stuffed animals (one such specimen made an appearance on this blog a few years ago).

This week, however, having nothing better to do, I extracted a book of owls (namely Owls of the World: their evolution, structure and ecology, edited by John A. Burton) from a bookshelf, sketched a few of the owls, and was inspired to write a post about them.

It should be noted, to begin with, that although owls are generally charming by virtue of their large eyes, there are exceptions. The great grey owl, for example, has a large, pancake-like face with small, close-set yellow eyes (and no ear tufts!). As for the barn owl (and owls of the genus Tyto in general), its features are reminiscent of a human face, except with beady black eyes, no mouth, and a beak where the tip of the nose should be -- not very appealing.

Anyway, what struck and amused me while flipping through the book of owls was how expressive owls can be. Witness, for example, the following sketches (of a snowy owl and a bare-shanked screech owl, both based on photos in the book):

Owls

I especially like the snowy owl and its look of mixed triumph and contempt, even though it must be said that, in the original photo, the owl's bearing and expression are more leery (hence more amusing) and the effect is made more striking by the redness of the eye.

Snowy Owl

Below is a reddish scops owl of Malaysia -- chosen because of its fluffball-like proportions and because, in the photo, the intensity of its gaze is augmented by bright orange-yellow eyes.

Scops Owl

The owl in the next (and last) sketch is a spotted eagle owl (of Africa). The owl's head really is rather square from that angle, but was rendered more so by my lack of skill.

Spotted Eagle Owl

To finish off, I present you with the amazing transformative powers of a northern white-faced owl (his name is Popo-chan, also of Africa):


Note the expression of utter scorn at 1:45. By the way, in case the embedded video doesn't work, it can also be watched in non-embedded form on YouTube.