Ahmed Adamjee / Mbed 2 deprecated SnakeVSBlock

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
AhmedPlaymaker
Date:
Tue Apr 09 05:32:54 2019 +0000
Parent:
19:05cc9f801468
Child:
21:e41126528cc6
Commit message:
Made initial levels easier and made a fun transition between levels

Changed in this revision

Snake/Snake.cpp Show annotated file Show diff for this revision Revisions of this file
Snake/Snake.h Show annotated file Show diff for this revision Revisions of this file
SnakevsBlock/SnakevsBlock.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Snake/Snake.cpp	Mon Apr 08 16:46:14 2019 +0000
+++ b/Snake/Snake.cpp	Tue Apr 09 05:32:54 2019 +0000
@@ -28,7 +28,7 @@
 }
 
 
-int Snake::draw(Gamepad &pad, N5110 &lcd, int length)
+int Snake::draw(Gamepad &pad, N5110 &lcd, int length, int level)
 {   
     if(m == 0){
         _x = WIDTH/2;  //Spawns player sprite near the middle of the screen.
@@ -245,6 +245,26 @@
         lcd.printString("Level Complete",0,1);
         lcd.refresh();
         wait(1);
+        lcd.clear();
+        lcd.printString("Press Start",3,1);
+        lcd.printString("to Proceed",5,3);
+        lcd.refresh();
+        int sound = 1000;
+        while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+            pad.leds_on();
+            pad.tone(rand()%sound,0.1);
+            wait(0.1);
+            pad.leds_off();
+            wait(0.1);
+        }
+        wait(1);
+        lcd.clear();
+        char bufferlevel[14];
+        sprintf(bufferlevel,"%d",level);
+        lcd.printString("Level:",25,1);
+        lcd.printString(bufferlevel,40,3);
+        lcd.refresh();
+        wait(2);
         length = 3;
     }
     return length;
--- a/Snake/Snake.h	Mon Apr 08 16:46:14 2019 +0000
+++ b/Snake/Snake.h	Tue Apr 09 05:32:54 2019 +0000
@@ -24,7 +24,7 @@
     *
     *   This function draws the Snake sprite onto the screen at the specified coordinates.
     */
-    int draw(Gamepad &pad, N5110 &lcd, int length);
+    int draw(Gamepad &pad, N5110 &lcd, int length, int level);
     
     /** Update
     *
--- a/SnakevsBlock/SnakevsBlock.cpp	Mon Apr 08 16:46:14 2019 +0000
+++ b/SnakevsBlock/SnakevsBlock.cpp	Tue Apr 09 05:32:54 2019 +0000
@@ -18,7 +18,7 @@
     foodbuff = 0;
     send=0;
     speed = 1;
-    blockgap = 161;
+    blockgap = 500;
     blockbuff = 0;
     b0 = 1;
     b1 = 1;
@@ -47,7 +47,7 @@
 
 void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad)
 {
-    length = _s.draw(pad, lcd, length); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
+    length = _s.draw(pad, lcd, length, level); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
     if(foodbuff >=0)  {
         _f.draw(lcd); //Draws the first food.
         if(foodbuff >=50)  {
@@ -94,8 +94,14 @@
     if(blockbuff == blockgap)  {  //change this while changing the block drop gap
         blockbuff = 0;
     }
+    if(length >= 11)  {  //change this while changing the block drop gap
+        speed = 2;
+    }
+    else  {
+        speed = 1;
+    }
     if(length > 15)  {  //change this while changing the block drop gap
-        blockgap -= 10;
+        blockgap -= 20;
         level += 1;
     }
 }