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

Committer:
jd0205
Date:
Thu Mar 17 18:33:52 2016 +0000
Revision:
0:5d811b6879d5
Child:
1:8dd8fafa7fc8
This is the first version of a Fishing Mini-game.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jd0205 0:5d811b6879d5 1 #include "globals.h"
jd0205 0:5d811b6879d5 2
jd0205 0:5d811b6879d5 3 class Fishing
jd0205 0:5d811b6879d5 4 {
jd0205 0:5d811b6879d5 5 public:
jd0205 0:5d811b6879d5 6 Fishing();
jd0205 0:5d811b6879d5 7 void start();
jd0205 0:5d811b6879d5 8 void lake_init();
jd0205 0:5d811b6879d5 9 void grass(int x, int y, int n, int color);
jd0205 0:5d811b6879d5 10 void draw_fish(int x, int dist);
jd0205 0:5d811b6879d5 11 void draw_rod(int n, int x);
jd0205 0:5d811b6879d5 12
jd0205 0:5d811b6879d5 13 private:
jd0205 0:5d811b6879d5 14 int oldx;
jd0205 0:5d811b6879d5 15 int oldx2;
jd0205 0:5d811b6879d5 16 int oldCnt;
jd0205 0:5d811b6879d5 17 };
jd0205 0:5d811b6879d5 18
jd0205 0:5d811b6879d5 19 Fishing::Fishing() {
jd0205 0:5d811b6879d5 20 oldx = 0;
jd0205 0:5d811b6879d5 21 oldx2 = 64;
jd0205 0:5d811b6879d5 22 oldCnt = 1;
jd0205 0:5d811b6879d5 23 }
jd0205 0:5d811b6879d5 24
jd0205 0:5d811b6879d5 25 void Fishing::start() {
jd0205 0:5d811b6879d5 26 stdio_mutex.lock();
jd0205 0:5d811b6879d5 27 uLCD.text_width(1);
jd0205 0:5d811b6879d5 28 uLCD.text_height(1);
jd0205 0:5d811b6879d5 29 uLCD.printf("Fishing Simulator V1.0");
jd0205 0:5d811b6879d5 30 wait(2.0);
jd0205 0:5d811b6879d5 31 stdio_mutex.unlock();
jd0205 0:5d811b6879d5 32 }
jd0205 0:5d811b6879d5 33
jd0205 0:5d811b6879d5 34 void Fishing::lake_init() {
jd0205 0:5d811b6879d5 35 stdio_mutex.lock();
jd0205 0:5d811b6879d5 36 uLCD.filled_rectangle(0, 0 , 127, 127, BLACK);
jd0205 0:5d811b6879d5 37 for(int i =0; i < 17; i++) {
jd0205 0:5d811b6879d5 38 uLCD.line(0, 23+i, 127, 23+i, i*0x000F);
jd0205 0:5d811b6879d5 39 }
jd0205 0:5d811b6879d5 40 uLCD.filled_rectangle(0, 40, 127, 127, BLUE);
jd0205 0:5d811b6879d5 41 uLCD.line(88, 40, 108, 108, RED);
jd0205 0:5d811b6879d5 42 uLCD.line(20, 108, 40, 40, RED);
jd0205 0:5d811b6879d5 43 stdio_mutex.unlock();
jd0205 0:5d811b6879d5 44 }
jd0205 0:5d811b6879d5 45
jd0205 0:5d811b6879d5 46 void Fishing::grass(int x, int y, int n, int color) {
jd0205 0:5d811b6879d5 47 uLCD.circle(x+2*n-2, y+4*n , n, 0x000042);
jd0205 0:5d811b6879d5 48 uLCD.circle(x+2*n+1, y+4*n , n, 0x000042);
jd0205 0:5d811b6879d5 49 uLCD.circle(x+2*n-2, y+4*n , n-1, 0x444444);
jd0205 0:5d811b6879d5 50 uLCD.circle(x+2*n+1, y+4*n , n-1, 0x444444);
jd0205 0:5d811b6879d5 51 uLCD.filled_circle(x+2*n-2, y+4*n , n-2, 0x000042);
jd0205 0:5d811b6879d5 52 uLCD.filled_circle(x+2*n+1, y+4*n , n-2, 0x000042);
jd0205 0:5d811b6879d5 53 uLCD.filled_circle(x+2*n-1, y+4*n , n-2, 0x000042);
jd0205 0:5d811b6879d5 54 for (int i = n; i < 2*n; i++) {
jd0205 0:5d811b6879d5 55 uLCD.line(x, y+2*n, x+i, y + 4*n, color - (0x000500 * i));
jd0205 0:5d811b6879d5 56 }
jd0205 0:5d811b6879d5 57 for (int j = 2*n; j < 3*n; j++) {
jd0205 0:5d811b6879d5 58 uLCD.line(x, y+2*n, x+j, y + 4*n, color - (0x000500 * j));
jd0205 0:5d811b6879d5 59 uLCD.line(x+n, y, x+j, y + 4*n, color - (0x000500 * j));
jd0205 0:5d811b6879d5 60 uLCD.line(x+4*n, y+n, x+j, y + 4*n, color - (0x000500 * j));
jd0205 0:5d811b6879d5 61 }
jd0205 0:5d811b6879d5 62 }
jd0205 0:5d811b6879d5 63
jd0205 0:5d811b6879d5 64 void Fishing::draw_fish(int x, int dist) {
jd0205 0:5d811b6879d5 65 stdio_mutex.lock();
jd0205 0:5d811b6879d5 66 if(oldx != x) {
jd0205 0:5d811b6879d5 67 uLCD.filled_circle(oldx, 80 , 4, BLUE);
jd0205 0:5d811b6879d5 68 oldx = x;
jd0205 0:5d811b6879d5 69 uLCD.circle(x-1, 80 , 3, 0x000042);
jd0205 0:5d811b6879d5 70 uLCD.circle(x+1, 80 , 3, 0x000042);
jd0205 0:5d811b6879d5 71 uLCD.circle(x-1, 80 , 2, 0x444444);
jd0205 0:5d811b6879d5 72 uLCD.circle(x+1, 80 , 2, 0x444444);
jd0205 0:5d811b6879d5 73 uLCD.filled_circle(x, 80 , 1, 0x000042);
jd0205 0:5d811b6879d5 74 uLCD.filled_circle(x+1, 80 , 1, 0x000042);
jd0205 0:5d811b6879d5 75 }
jd0205 0:5d811b6879d5 76 uLCD.locate(7,15);
jd0205 0:5d811b6879d5 77 uLCD.printf("%d", dist);
jd0205 0:5d811b6879d5 78 stdio_mutex.unlock();
jd0205 0:5d811b6879d5 79 }
jd0205 0:5d811b6879d5 80
jd0205 0:5d811b6879d5 81 void Fishing::draw_rod(int n, int x) {
jd0205 0:5d811b6879d5 82 if (oldCnt != n || oldx2 != x) {
jd0205 0:5d811b6879d5 83 stdio_mutex.lock();
jd0205 0:5d811b6879d5 84 uLCD.line(64 + 6*oldCnt,95, 64 + 7*oldCnt, 100, BLUE);
jd0205 0:5d811b6879d5 85 uLCD.line(64 + 7*oldCnt,99, 64 + 8*oldCnt, 106, BLUE);
jd0205 0:5d811b6879d5 86 uLCD.line(64 + 8*oldCnt,106, 64 + 7*oldCnt, 115, BLUE);
jd0205 0:5d811b6879d5 87 uLCD.line(64 + 7*oldCnt,115, 64, 127, BLUE);
jd0205 0:5d811b6879d5 88 uLCD.line(oldx2, 80, 64 + 6*oldCnt, 95, BLUE);
jd0205 0:5d811b6879d5 89 oldCnt = n;
jd0205 0:5d811b6879d5 90 oldx2 = x;
jd0205 0:5d811b6879d5 91 uLCD.line(64 + 6*n,95, 64 + 7*n, 100, 0x964B00);
jd0205 0:5d811b6879d5 92 uLCD.line(64 + 7*n,99, 64 + 8*n, 106, 0x964B00);
jd0205 0:5d811b6879d5 93 uLCD.line(64 + 8*n,106, 64 + 7*n, 115, 0x964B00);
jd0205 0:5d811b6879d5 94 uLCD.line(64 + 7*n,115, 64, 127, 0x964B00);
jd0205 0:5d811b6879d5 95 uLCD.line(x, 80, 64 + 6*n, 95, WHITE);
jd0205 0:5d811b6879d5 96 stdio_mutex.unlock();
jd0205 0:5d811b6879d5 97 }
jd0205 0:5d811b6879d5 98 }