Games I’ve Coded – Snake EX2

Steve on Aug 23rd 2009

My next game in the “Games I’ve Coded” series is Snake EX2, originally available with the Nokia 3300.

Snake EX2 Title

Nokia 3300

From what I remember, I’m going pretty much in chronological order of Nokia embedded ‘white label’ games at the moment.  There’s one more game to go for Nokia and one more application that wasn’t a game but more of a handy utility.  I wish I could find the time at the moment to write more, and I’d love to get a post in about my companies latest product as soon as it’s available and I can talk about it publicly.  I’m probably going to jump around a bit then with games I’ve coded and cherry pick the good ones that will make for some interesting writing.

I’m really glad I can say I wrote a Snake game on mobile.  Even today, when I tell almost anyone what I do for a living, they know what Snake is.  It’s one of those milestone beacons in the mobile game industry that shines out into the wider media and public consciousness.  Of course, I didn’t come up with the Snake idea, and even the code base for Snake EX2 was an iteration of the J2ME version of Snake 2, done by my then colleague Nick Slaven, but at least I can truthfully answer yes when anyone says “You do mobile phone games eh?  Like Snake?”.

Snake_128x128_001

There nothing very technically interesting to say about the Snake code really.  It consists of the usual small number of J2ME essentials, a MIDlet, Canvas, TimerTask, a game engine class and a couple of extras like a custom gauge canvas for picking the difficulty level and two classes for the sound code.  The game was designed to use the (then new) Multimedia API for J2ME which was included with the 3300, but it also needed to work on phones without the MMAPI, so it had a fallback using old style Nokia ringtone audio.  Total lines of code came to ~5000.  As you can imagine,  Snake isn’t very heavy on the resources either.  12 midi files for the audio effects and 8 differnet PNG images for the graphics, not including the title screen, were all that was needed.

One thing that I do remember is the way that the game only updated the screen where necessary each frame.  These days, it’s pretty common to do a full screen refresh each frame on mobile games, but on the older devices, it was worth being careful about full screen updates.  In Snake, only the head, tail and any food that popped in or out needed to be updated each frame.  Doing this meant the frame rate would keep to a steady 15 fps no matter how long the snake got.

You might notice there isn’t a background ‘texture’ to the playing area, it’s a plain colour.  We originally had a sand like background tile, but when we finally got a real device to test with, the screen quality was quite poor.  It couldn’t cope with the background pattern and there was a noticeable pixel crawl that occurred, so we had to get rid of it before the game was finished.

sand tile

If you search YouTube, you can find various videos of people getting massive scores on Snake games, including EX2.  One even shows a nice bug where the food spawns over the snake when it’s really long and fills the screen.  It  doesn’t seem to crash the game or cause a problem, except for having to keep moving the snake until the food gets free before eating it!  Nokia QA must have missed that one.

Share this post:
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • Google Bookmarks
  • Facebook
  • StumbleUpon
  • Twitter

Filed in Games | No responses yet

Trackback URI | Comments RSS

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word