A simple two button snake.
A Snake Game with animation, score and continuous play
Steps:
- Switch On.
- Snake animation plays.
- Game starts.
- Press buttons to move the snake left, right, up and down.
- Food appears as a dot on the display.
- Try eating the food by manoeuvring Snake to run over it.
- Snake grows as it eats food.
- As it grows it becomes hard to avoid snake biting itself.
- Game Over.
- Snake is flashed and then score is scrolled.
- Game restarts after replaying animation.
Controls:
- Left Button (A)
- If snake moving UP/DOWN moves snake to LEFT.
- If snake moving LEFT moves snake to DOWN.
- If snake moving RIGHT moves snake to UP.
- Right Button (B)
- If snake moving UP/DOWN moves snake to RIGHT.
- If snake moving LEFT moves snake to UP.
- If snake moving RIGHT moves snake to DOWN.
How it looks:
https://www.youtube.com/watch?v=unEs3NOvIKA
Binary to play with
/media/uploads/mazimkhan/microbit_snake_nrf51_microbit.hex
Diff: main.cpp
- Revision:
- 4:9fd9402eca3d
- Parent:
- 3:a0200bceae4b
- Child:
- 5:9328487a0a46
diff -r a0200bceae4b -r 9fd9402eca3d main.cpp --- a/main.cpp Sun Apr 10 23:31:53 2016 +0000 +++ b/main.cpp Tue Apr 12 12:08:38 2016 +0000 @@ -341,12 +341,6 @@ Dimension nextX = snake.getHeadX(); Dimension nextY = snake.getHeadY(); - // Check snake bite - if (image.getPixelValue(nextX, nextY) == 15){ - // Game Over - return false; - } - // check if we grew by eating. if (nextX == foodx && nextY == foody){ // food gone @@ -365,6 +359,12 @@ snake.reduce(); } + // Check snake bite + if (image.getPixelValue(nextX, nextY) == 15){ + // Game Over + return false; + } + // Turn On head. image.setPixelValue(nextX, nextY, SNAKE_HEAD_PIXEL_BRIGHTNESS); uBit.display.print(image); @@ -538,7 +538,7 @@ uBit.display.print(MicroBitImage(5,5)); uBit.display.setBrightness(255); uBit.display.scroll("SCORE-"); // don't mind spaces in a scrolling display. - uBit.display.scroll(score, 300); + uBit.display.scroll(score, 150); } void reset(){