Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
26:3495f7b0ede7
Parent:
21:e41126528cc6
Child:
28:d2c621d67e3b
--- a/StartScreen/StartScreen.cpp	Wed Apr 10 14:37:05 2019 +0000
+++ b/StartScreen/StartScreen.cpp	Thu Apr 11 05:34:03 2019 +0000
@@ -130,115 +130,17 @@
 
 void StartScreen::screen_saver(N5110 &lcd, Gamepad &pad)
 {
-    int ani = -48;
+    int song[18] = {441,494,439,372,392,370,330,246,329,331,370,555,555,495,440,392,392,370};
     pad.leds_on();
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(440,0.1);
-    wait(0.1);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(494,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(440,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(370,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(392,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(370,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(330,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(247,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(330,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(330,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(370,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(555,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(555,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(494,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(440,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(392,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(392,0.1);
-    wait(0.2);
-    lcd.clear();
-    lcd.drawSprite(0,0,48,84,(int *)sprite); //Function used to draw the sprite
-    ani+=3;
-    lcd.refresh();
-    pad.tone(370,0.1);
+    
+    for(int ani = -48; ani <= 0; ani+=3)  {
+        lcd.clear();
+        lcd.drawSprite(0,ani,48,84,(int *)sprite); //Function used to draw the sprite
+        lcd.refresh();
+        pad.tone(song[(ani+48)/3],0.1);
+        wait(0.2);
+    }
+    
     wait(0.3);
     pad.leds_off();
     lcd.clear();
@@ -308,65 +210,45 @@
     }
     else if(i == 24)
     {
-        lcd.clear();
         settings.info(lcd, pad);
         wait(1/cs);
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {  //if button pressed.
         
         Direction d = pad.get_direction();
         wait(1/cs);
-    
+        lcd.clear();
+        
         if((d==E)&&(st==5))  {
             st=1;
         }
-        
         else if((d==W)&&(st==1))  {
             st=5;
         }
-        
         else if((d==E)&&(1<=st<=4))  {
             st=st+1;
         }
-        
         else if((d==W)&&(2<=st<=5))  {
             st=st-1;
         }
         
+        lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
+        lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
         if(st==1)  { 
-            lcd.clear();
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
             cs = settings.controlSensitivity(lcd, pad);
-            lcd.refresh();
         }
         if(st==2)  {
-            lcd.clear();
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
             settings.brigntness(lcd, pad);
-            lcd.refresh();
         }
         if(st==3)  {
-            lcd.clear();
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
             settings.contrast(lcd, pad);
-            lcd.refresh();
         }
         if(st==4)  {
-            lcd.clear();
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
             settings.volume(lcd, pad);
-            lcd.refresh();
         }
         if(st==5)  {
-            lcd.clear();
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
             sc = settings.showCredits(lcd, pad);
-            lcd.refresh();
-        }
+        } 
+        lcd.refresh();
     }
     pad.tone(1000.0,0.1);
     menu_screen1(lcd, pad);
@@ -383,10 +265,13 @@
     lcd.clear();
     wait(2/cs);
     while ((pad.check_event(Gamepad::JOY_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.
-        
+
         Direction d = pad.get_direction();
-        wait(1/cs);
-    
+        lcd.clear();
+        lcd.drawRect(27,18,30,20,FILL_TRANSPARENT);
+        lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
+        lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
+        
         if(((d==E)||(d==W))&&(lr==1))  {
             lr=2;
         }
@@ -396,31 +281,21 @@
         }
         
         if(lr==1)  {
-            lcd.clear();
-            lcd.drawRect(27,18,30,20,FILL_TRANSPARENT);
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
             lcd.printString("Free Wave",14,1);
             lcd.refresh();
         }
         if(lr==2)  {
-            lcd.clear();
-            lcd.drawRect(27,18,30,20,FILL_TRANSPARENT);
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
             lcd.printString("Bullet Shower",4,1);
             lcd.drawSprite(29,19,13,5,(int *)bullet); //Function used to draw the sprite.
-            lcd.refresh();
         }
         wait(1/cs);
         if (pad.check_event(Gamepad::BACK_PRESSED) == true) { 
-            lcd.clear();
             pad.tone(1000.0,0.1);
             menu_screen1(lcd, pad);
-        }   
+        }
+        lcd.refresh();
     }
     pad.tone(1000.0,0.1);
-    
     lcd.clear();
     wait(1/cs);
     menu_screen3(lcd, pad);
@@ -438,68 +313,48 @@
         if((d==E)&&(gs==4))  {
             gs=1;
         }
-        
         else if((d==W)&&(gs==1))  {
             gs=4;
         }
-        
         else if((d==E)&&(1<=gs<=3))  {
             gs=gs+1;
         }
-        
         else if((d==W)&&(2<=gs<=4))  {
             gs=gs-1;
         }
-        
+        lcd.clear();
+        lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
+        lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
+        lcd.printString("Game Speed",10,1);
         if(gs==1)  {
-            lcd.clear();
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
-            lcd.printString("Game Speed",10,1);
             lcd.printString("SNAIL",26,3);
             fps = 10;
-            lcd.refresh();
         }
         if(gs==2)  {
-            lcd.clear();
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
-            lcd.printString("Game Speed",10,1);
             lcd.printString("TURTLE",24,3);
             fps = 18;
-            lcd.refresh();
         }
         if(gs==3)  {
-            lcd.clear();
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
-            lcd.printString("Game Speed",10,1);
             lcd.printString("RABBIT",24,3);
             fps = 25;
-            lcd.refresh();
         }
         if(gs==4)  {
-            lcd.clear();
-            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
-            lcd.printString("Game Speed",10,1);
             lcd.printString("CHEETHA",21,3);
             fps = 33;
-            lcd.refresh();
         }
         
         if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
-            lcd.clear();
             wait(1/cs);
             pad.tone(1000.0,0.1);
             menu_screen2(lcd, pad);
         }
+        lcd.refresh();
     }
     
     pad.tone(1000.0,0.1);
     lcd.clear();
     wait(1/cs);
-    lcd.printString("Level:",25,1); //created so that the gamer can keep track of their game.
+    lcd.printString("Level:",25,1); //created so that the gamer can keep track of their game. //change this to be operated remotely
     lcd.printString("1",40,3);
     lcd.refresh();
     wait(2);