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, committed 2016-03-17
- Comitter:
- jd0205
- Date:
- Thu Mar 17 18:47:33 2016 +0000
- Parent:
- 0:5d811b6879d5
- Commit message:
- Added comments
Changed in this revision
diff -r 5d811b6879d5 -r 8dd8fafa7fc8 Fish.h --- a/Fish.h Thu Mar 17 18:33:52 2016 +0000 +++ b/Fish.h Thu Mar 17 18:47:33 2016 +0000 @@ -26,9 +26,9 @@ } else { dir = -1; } - size = (rand() % 100) + 20; - time = ((rand() % 5) + 1)*5; - clk = 0; + size = (rand() % 100) + 20; //Size of the fish will determine how fast it can move + time = ((rand() % 5) + 1)*5; //Time determines how long it will either head left or right + clk = 0; //Shows how much time has passed } void Fish::reset() { @@ -52,11 +52,11 @@ return y_pos; } -void Fish::move(int n) { +void Fish::move(int n) { //Changes the x-position of the fish or moves it x_pos = x_pos + n; } -void Fish::movement() { +void Fish::movement() { //The movement of the fish, basically going back and forth if(clk >= time) { clk = 0; time = ((rand() % 5) + 1)*5; @@ -71,7 +71,7 @@ } } -bool Fish::failed() { +bool Fish::failed() { //When it reaches the outer bounds, the fish has escaped if(x_pos < 30 || x_pos > 98) { return false; } else {
diff -r 5d811b6879d5 -r 8dd8fafa7fc8 Fishing.h --- a/Fishing.h Thu Mar 17 18:33:52 2016 +0000 +++ b/Fishing.h Thu Mar 17 18:47:33 2016 +0000 @@ -22,7 +22,7 @@ oldCnt = 1; } -void Fishing::start() { +void Fishing::start() { //Title Screen stdio_mutex.lock(); uLCD.text_width(1); uLCD.text_height(1); @@ -31,7 +31,7 @@ stdio_mutex.unlock(); } -void Fishing::lake_init() { +void Fishing::lake_init() { //Initial lake or pond stdio_mutex.lock(); uLCD.filled_rectangle(0, 0 , 127, 127, BLACK); for(int i =0; i < 17; i++) { @@ -43,7 +43,7 @@ stdio_mutex.unlock(); } -void Fishing::grass(int x, int y, int n, int color) { +void Fishing::grass(int x, int y, int n, int color) { //Drawing of the grass uLCD.circle(x+2*n-2, y+4*n , n, 0x000042); uLCD.circle(x+2*n+1, y+4*n , n, 0x000042); uLCD.circle(x+2*n-2, y+4*n , n-1, 0x444444); @@ -61,7 +61,7 @@ } } -void Fishing::draw_fish(int x, int dist) { +void Fishing::draw_fish(int x, int dist) { //Drawing of the fish stdio_mutex.lock(); if(oldx != x) { uLCD.filled_circle(oldx, 80 , 4, BLUE); @@ -78,7 +78,7 @@ stdio_mutex.unlock(); } -void Fishing::draw_rod(int n, int x) { +void Fishing::draw_rod(int n, int x) { //Drawing of the fishing rod if (oldCnt != n || oldx2 != x) { stdio_mutex.lock(); uLCD.line(64 + 6*oldCnt,95, 64 + 7*oldCnt, 100, BLUE);
diff -r 5d811b6879d5 -r 8dd8fafa7fc8 main.cpp --- 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);