Dependencies:   mbed

Snake Game

Summary

Hello and welcome to my Snake Game. Snake is a simple game where you control a snake and eat an apple which increases your size. Normally touching the walls will kill you, always touching yourself will make you die!

Controls

The Controls for this game are simple the Start button starts the game (who would have thought) this button is the left button on the bottom of the gamepad next to the two blue potentiometers. The Reset button on the right of the potentiometers resets the game. Once the game starts use the left thumbstick to control the movement of the snake.

If you hit the wall with your snake you will die and the game will end.

Bugs/Missing Features

Unfortunatley I wasn't able to get the game eating the apple to work, when I tried I could never get it to detect the collisions I tried a few different ways but ran out of time. Because that doesn't work the score doesn't increase and the apple doesn't spawn in a different place. I will try continue to work on this when I have time as I enjoyed doing this project even though it was very frustrating at times!

Revision:
13:c20acb3b1adf
Parent:
12:8eb40a18f15d
Child:
14:8d12bc972cb1
--- a/Snake/Snake.cpp	Fri Jun 05 20:47:43 2020 +0000
+++ b/Snake/Snake.cpp	Fri Jun 05 22:13:33 2020 +0000
@@ -11,11 +11,13 @@
 
 }
 
-void Snake::init(int x,int y, int score, int speed) //Initial values for the snake
+void Snake::init(int x,int y, int score, int speed, int snakeheight, int snakewidth) //Initial values for the snake
 {
     _x = WIDTH/2; // Sets the position to be in the middle of the screen
     _y = HEIGHT/2;
     _speed = speed; // The value that holds the speed of the snake
+    _snakewidth = snakewidth;
+    _snakeheight = snakeheight;
 
 
 }
@@ -24,7 +26,7 @@
 {
  
     // draw Snake in screen buffer. 
-  lcd.drawRect(_x,_y,5,5,FILL_BLACK);  // Draws the initial snake head is a 5x5 Square matches well with the cirlce of the apple when set to 2
+  lcd.drawRect(_x,_y,_snakewidth,_snakeheight,FILL_BLACK);  // Draws the initial snake head is a 5x5 Square matches well with the cirlce of the apple when set to 2
 
 }
 
@@ -99,6 +101,6 @@
 
 
 Vector2D Snake::get_pos() { //Gets the position of the snake this will be used for collision detection soon
-    Vector2D pos = {_x,_y};
-    return pos;    
+    Vector2D p = {_x,_y};
+    return p;    
 }
\ No newline at end of file