ELEC2645 (2015/16) / Mbed 2 deprecated SnakeProjectRev1

Dependencies:   Joystick N5110 SDFileSystem beep fsmMenu mbed

Fork of SnakeProjectRev1 by Meurig Phillips

Revision:
7:f7f2abab16ef
Parent:
6:9a5706a27240
Child:
8:9b767dd1e549
--- a/main.cpp	Thu Apr 07 20:45:07 2016 +0000
+++ b/main.cpp	Fri Apr 22 13:03:15 2016 +0000
@@ -21,10 +21,10 @@
  
 // connections for joystick
 DigitalIn button(PTB18);
-AnalogIn xPot(PTC11);
-AnalogIn yPot(PTC10);
+AnalogIn xPot(PTB2);
+AnalogIn yPot(PTB3);
 
-PwmOut greenLed(PTA1);
+//PwmOut greenLed(PTC2);
 
 // timer to regularly read the joystick
 Ticker pollJoystick;
@@ -90,6 +90,7 @@
 int prev2_i = 41;
 int prev2_j = 23;
 
+
 bool gamePlaying = false;
 
 // function prototypes
@@ -111,7 +112,7 @@
 {
     
     calibrateJoystick();  // get centred values of joystick
-    pollJoystick.attach(&updateJoystick,1.0/10.0);  // read joystick 10 times per second
+    pollJoystick.attach(&updateJoystick,0.5/10.0);  // read joystick 10 times per second
     
     srand(time(NULL));
       
@@ -120,6 +121,7 @@
     //hardWall();
     generateFood();
     gamePlaying = true;
+  //  greenLed = 0;
  
     while(1) {
         
@@ -162,9 +164,9 @@
     } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
         joystick.direction = DOWN;
     } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
-        joystick.direction = RIGHT;
+        joystick.direction = LEFT;
     } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
-        joystick.direction = LEFT;
+        joystick.direction = RIGHT;
     } else {
         joystick.direction = UNKNOWN;
     }
@@ -293,22 +295,22 @@
                 lcd.refresh();
                 
                 lcd.drawRect(randomX,randomY,1,1,1); // food
-                //hardWall();
+                hardWall();
                 //specialMap();
-                wrapAround();
+                //wrapAround();
                 
                 if (i == randomX && j == randomY) { // if fruit is eaten
-                    greenLedFlash();
+                    //greenLedFlash();
                     scoreCalculation();
                     snakeTailLength++;
                     newFruitXY();
                     generateFood();  
                     }
-                wait(1.0);
+                wait(0.5);
     
  }
  
-void greenLedFlash() {
+/*void greenLedFlash() {
      
      for(float p = 1.0f; p > 0.0f; p -= 0.1f) { // green led rapidly decreases from full brightness to off
             greenLed = p;
@@ -316,7 +318,7 @@
         }
         greenLed = 0;
      
-}
+} */
 
 void hardWall() {
 
@@ -382,7 +384,7 @@
       
 }
 
-void wrapAround() {
+/*void wrapAround() {
 
     if (i == -1) {
         i = 83;
@@ -394,7 +396,7 @@
         j = 47;
         }
     if (j+1 == 48) {
-        j = -1;
+        j+1 = 0;
         }    
     
     lcd.setPixel(i,j);
@@ -411,7 +413,7 @@
     lcd.setPixel(prev2_i+1,prev2_j);
     
     lcd.refresh();
-}
+} */
 
 
 void scoreCalculation() {