Snake for Arduino Esplora

This is a sketch for Arduino Esplora with TFT screen.It is a porting of the famous game Snake completely rewritten for this platform. The snake is drown on the screen and its motion is obtained adding another block in front of it and deleting the last one so it seems that the snake is moving. To choose the snake motion direction you have to press the buttons of Arduino Esplora. There is a green beacon on the screen which is the target of the game. You have to eat the beacon with the snake and for each eaten beacon you earn 9 points. You can choose also the speed of the snake through the slider. The code is highly commented so it would be easy to know what it is doing.

Click the button to show the code.

The snake positions are saved into array positions and positions are updated according to the selected speed (by the slider). There are 4 types of motion, one for each direction, and so there are four cases in moveTheSnake function. If a beacon is eaten the last block of the snake is not deleted and snakeLenght is increased, otherwise when the position is updated the last block is deleted printing it black. Also the score is updated printing it black and reprinting the new one in white. All this is done because in such a way the refreshing procedure will be faster than updating all the screen (remember we have a 16 Mhz micro). The beacon is placed on the screen by a random way. The random sequence is initialized with the temperature sensor. If there are more sketch problems feel free to comment.

Happy sketching.

No comments:

Post a Comment