This is the first version of a Fishing Mini-game. It uses a navigational switch as a button and a joystick, playing wav files from a SD card, and a uLCD screen to show the fishing game

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Revision:
1:8dd8fafa7fc8
Parent:
0:5d811b6879d5
--- a/main.cpp	Thu Mar 17 18:33:52 2016 +0000
+++ b/main.cpp	Thu Mar 17 18:47:33 2016 +0000
@@ -30,7 +30,7 @@
 bool lure = false;
 bool success = false;
 
-void lakeside_thread(void const *args) {
+void lakeside_thread(void const *args) {        //This is a thread that displays moving pieces of grass to mimic movement.
     while(1) {
         stdio_mutex.lock();
         rem1 = dist%20;
@@ -67,19 +67,19 @@
     FILE *wave_file;
     while(true) {
         while(lure) {
-            wave_file=fopen("/sd/wavfiles/Water Drop.wav","r");
+            wave_file=fopen("/sd/wavfiles/Water Drop.wav","r");         //Sound for casting a lure
             waver.play(wave_file);
             fclose(wave_file);
             Thread::wait(5000);
         }
         while(fishing) {
-            wave_file=fopen("/sd/wavfiles/Stream Noise.wav","r");
+            wave_file=fopen("/sd/wavfiles/Stream Noise.wav","r");       //Sound for reeling in the fish
             waver.play(wave_file);
             fclose(wave_file);
             Thread::wait(50);
         }
         while(success) {
-            wave_file=fopen("/sd/wavfiles/Fish Splashing.wav","r");
+            wave_file=fopen("/sd/wavfiles/Fish Splashing.wav","r");     //Sound of catching a fish
             waver.play(wave_file);
             fclose(wave_file);
             Thread::wait(1000);
@@ -89,8 +89,8 @@
 
 int main() {
     dist = 0;
-    uLCD.baudrate(3000000);
-    fishing = false;
+    uLCD.baudrate(3000000);                         //Increase the baudrate to improve uLCD screen
+    fishing = false;                                //These bool will determine which track is playing in the sound thread.
     lure = false;
     success = false;
     
@@ -118,13 +118,13 @@
         stdio_mutex.unlock();
         if(rand1 > 80) {
             for(cnt = 0; cnt < 30; cnt++) {
-                mbedleds = 0x0F*(cnt%2);
-                uLCD.circle(64, 80 , 4+(cnt%8), BLACK );
+                mbedleds = 0x0F*(cnt%2);                        //When a fish is at the lure, the LEDs will blink
+                uLCD.circle(64, 80 , 4+(cnt%8), BLACK );        //And a ripple from the shadow will appear
                 uLCD.circle(64, 80 , 5+(cnt%8), BLACK );
                 uLCD.circle(64, 80 , 4+(cnt%8), BLUE);
                 uLCD.circle(64, 80 , 5+(cnt%8), BLUE);
-                if(myNav.fire()) {
-                    while(dist < 300) {
+                if(myNav.fire()) {                              //This gives the player 3 seconds to press the center
+                    while(dist < 300) {                         //of the Navigational Switch to start reeling it in.
                         dist = dist + 5;
                     }
                     fishing = true;
@@ -143,12 +143,12 @@
             fisher.draw_fish(fish1.x(), dist);
             fish1.movement();
             dist = dist - 2;
-            if (myNav.left()) {
-                cnt--;
+            if (myNav.left()) {                             //Pushing left will cause the fishing rod 
+                cnt--;                                      //To pull left
                 if (cnt > 0) {
                     cnt-=2;
                 }
-            } else if (myNav.right()) {
+            } else if (myNav.right()) {                     //Pushing right will cause the rod to pull right
                 cnt++;
                 if (cnt < 0) {
                     cnt+=2;
@@ -168,8 +168,8 @@
             fish1.move(((64+cnt*6 - fish1.x())/30) + 1);
             fisher.draw_rod(cnt, fish1.x());
             
-            if(dist == 0) {
-                success = true;
+            if(dist == 0) {                                     //When enough time has passed, the dist reaches 0
+                success = true;                                 //And it's a succesful capture of a fish
                 fishing = false;
                 stdio_mutex.lock();
                 fisher.lake_init();
@@ -180,8 +180,8 @@
                 stdio_mutex.unlock();
                 success = false;
             }
-            if (!(fish1.failed())) {
-                fishing = false;
+            if (!(fish1.failed())) {                            //If the fish escapes too far left or right
+                fishing = false;                                //The player has failed
                 stdio_mutex.lock();
                 fisher.lake_init();
                 uLCD.locate(1,1);