Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
13:9785f2404045
Parent:
12:1e601b176437
Child:
18:b391caa5754c
diff -r 1e601b176437 -r 9785f2404045 Blocks/Blocks.cpp
--- a/Blocks/Blocks.cpp	Tue Apr 02 17:06:22 2019 +0000
+++ b/Blocks/Blocks.cpp	Wed Apr 03 17:51:19 2019 +0000
@@ -271,7 +271,17 @@
     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
     {0,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
     };
-
+int Nothing[11][15] = {
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+    };
 
 int k = 0;
 void Blocks::init()
@@ -286,7 +296,6 @@
     _velocity.x = 0;
     _velocity.y = 1;
     
-    
     //Resets SnakeFood position if it reaches the bottom of the screen.
     //Also prevents SnakeFood from going out of the side of the screen.
     if(_bx < 0){
@@ -311,6 +320,9 @@
                 double round = length/(3/2);
                 caseselect[i] = floor(round);
             }
+            if(times == rand()%6)  {
+                caseselect[i] = 0;
+            }
             else    {
                 caseselect[i] = rand()%19;
             }
@@ -337,60 +349,63 @@
         state = caseselect[i];
         switch(state)  {
             case 0:
+                lcd.drawSprite(pos,_by,11,15,(int *)Nothing);
+                break;
+            case 1:
                 lcd.drawSprite(pos,_by,11,15,(int *)One);
                 break;
-            case 1:
+            case 2:
                 lcd.drawSprite(pos,_by,11,15,(int *)Two);
                 break;
-            case 2:
+            case 3:
                 lcd.drawSprite(pos,_by,11,15,(int *)Three);
                 break;
-            case 3:
-                lcd.drawSprite(pos,_by,11,15,(int *)Four);
-                break;
             case 4:
-                lcd.drawSprite(pos,_by,11,15,(int *)Five);
+                lcd.drawSprite(pos,_by,11,15,(int *)Four);
                 break;
             case 5:
-                lcd.drawSprite(pos,_by,11,15,(int *)Six);
+                lcd.drawSprite(pos,_by,11,15,(int *)Five);
                 break;
             case 6:
-                lcd.drawSprite(pos,_by,11,15,(int *)Seven);
+                lcd.drawSprite(pos,_by,11,15,(int *)Six);
                 break;
             case 7:
-                lcd.drawSprite(pos,_by,11,15,(int *)Eight);
+                lcd.drawSprite(pos,_by,11,15,(int *)Seven);
                 break;
             case 8:
-                lcd.drawSprite(pos,_by,11,15,(int *)Nine);
+                lcd.drawSprite(pos,_by,11,15,(int *)Eight);
                 break;
             case 9:
-                lcd.drawSprite(pos,_by,11,15,(int *)Ten);
+                lcd.drawSprite(pos,_by,11,15,(int *)Nine);
                 break;
             case 10:
-                lcd.drawSprite(pos,_by,11,15,(int *)Eleven);
+                lcd.drawSprite(pos,_by,11,15,(int *)Ten);
                 break;
             case 11:
-                lcd.drawSprite(pos,_by,11,15,(int *)Twelve);
+                lcd.drawSprite(pos,_by,11,15,(int *)Eleven);
                 break;
             case 12:
+                lcd.drawSprite(pos,_by,11,15,(int *)Twelve);
+                break;
+            case 13:
                 lcd.drawSprite(pos,_by,11,15,(int *)Thirteen);
                 break;
-            case 13:
+            case 14:
                 lcd.drawSprite(pos,_by,11,15,(int *)Fourteen);
                 break;
-            case 14:
+            case 15:
                 lcd.drawSprite(pos,_by,11,15,(int *)Fifteen);
                 break;
-            case 15:
-                lcd.drawSprite(pos,_by,11,15,(int *)Sixteen);
-                break;
             case 16:
-                lcd.drawSprite(pos,_by,11,15,(int *)Seventeen);
+                lcd.drawSprite(pos,_by,11,15,(int *)Sixteen);
                 break;
             case 17:
+                lcd.drawSprite(pos,_by,11,15,(int *)Seventeen);
+                break;
+            case 18:
                 lcd.drawSprite(pos,_by,11,15,(int *)Eighteen);
                 break;
-            case 18:
+            case 19:
                 lcd.drawSprite(pos,_by,11,15,(int *)Nineteen);
                 break;
             default: