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

Fish.h

Committer:
jd0205
Date:
2016-03-17
Revision:
0:5d811b6879d5
Child:
1:8dd8fafa7fc8

File content as of revision 0:5d811b6879d5:

class Fish
{
    public:
        Fish();
        void reset();
        int read();
        int x();
        int y();
        void move(int n);
        void movement();
        bool failed();
    private:
        int x_pos; 
        int y_pos;
        int dir;
        int size;
        int time;
        int clk;
};

Fish::Fish() {
    x_pos = 64;
    y_pos = 64;
    if (rand() % 100 > 50) {
        dir = 1;
    } else {
        dir = -1;
    }
    size = (rand() % 100) + 20;
    time = ((rand() % 5) + 1)*5;
    clk = 0;
}

void Fish::reset() {
    x_pos = 64;
    y_pos = 64;
    if (rand() % 100 > 50) {
        dir = 1;
    } else {
        dir = -1;
    }
    size = (rand() % 100) + 20;
    time = ((rand() % 5) + 1)*5;
    clk = 0;
}

int Fish::x() {
    return x_pos;
}

int Fish::y() {
    return y_pos;
}

void Fish::move(int n) {
    x_pos = x_pos + n;
}

void Fish::movement() {
    if(clk >= time) {
        clk = 0;
        time = ((rand() % 5) + 1)*5;
        dir = dir * -1;
    } else {
        if (clk < (size/15)) {
            move(dir * clk);
        } else {
            move(dir * (size/15));
        }
        clk++;
    }
}

bool Fish::failed() {
    if(x_pos < 30 || x_pos > 98) {
        return false;
    } else {
        return true;
    }
}