Brickley Roscowicz Engineering

Brickley Roscowicz Engineering


NXT Snake Game Print E-mail

See my other NXT Projects

December 2006

Snake is a well-known electronic game, where the user navigates an ever-growing "snake" around a screen, eating apples along the way.

After someone at NXTasy.org suggested it as a good use for a joystick control, I decided it could probably be done with just the NXT buttons and screen, and this program proves it can!

The snake is controlled by the 3 RCX buttons (the exit button cannot be used with the standard firmware). Left and right "turn" the snake 90º left or right (this method is often provided as an option to the N-S-E-W controls on other snake games), and the enter key pauses the game. Note that un-pausing with an arrow key causes the snake to turn.

The game starts of slowly, but as you reach higher scores, your level increases, along with the speed of the snake. And of course the snake grows every time he eats an apple! There are 9 levels, and you get 3 lives. And your NXT keeps a record of the highest score to date - to reset it, just delete the "snakehi.txt" file.

Also, as I wasn't getting good response only checking for button presses every time through the display loop, I implemented a queue for keypresses, via a separate thread. This improved the game playability a lot.

Note: I don't recommend this version for people with poor eyesight - I did consider increasing the snake width to 2 pixels, but decided I should leave something for others to experiment with :) It wouldn't be all that hard to do.

You will also start noticing considerable screen flicker as the snake length increases. It's still playable, but drawing on the screen does have it's limitations. I have noticed some hints in the NXCdefs.h file that the NXT actually has 2 screen buffers, and it may be possible to use double-buffering for screen writes. I will investigate that, and maybe use it in a future project if it works.

Anyway, click here for the NBC source code. You will need at least the beta 12 version of NBC for NXT Snake.