Menu class used as basis for program; running the game and allowing the user to change the style and difficulty of the game via an interface.
Diff: Menu.cpp
- Revision:
- 4:4f20bcef2c0c
- Parent:
- 3:a79daa7c2b55
- Child:
- 5:56f13954666e
--- a/Menu.cpp Sun Apr 16 12:31:48 2017 +0000 +++ b/Menu.cpp Mon May 01 09:13:40 2017 +0000 @@ -24,25 +24,32 @@ void Menu::init() { // set all default game parameters - _mazeIndex = 0; + _mazeIndex = 1; + _FPS = 50; + _control = true; _colour = true; + _tone = true; } /// MAIN MENU METHOD /// -void Menu::main(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, Sound &tune, Animations &animate) +void Menu::main(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, Animations &animate) { int selected = 0; while(1) { + pad.leds_off(); + char d = pad.get_direction(); if ((d == NW) || (d == N) || (d == NE)){ - tune.playTone(pad, 196.00, 0.20); + if (_tone){ + pad.tone(196.00, 0.20); + } selected -= 1; } @@ -50,7 +57,9 @@ (d == S) || (d == SE)){ - tune.playTone(pad, 196.00, 0.20); + if (_tone){ + pad.tone(196.00, 0.20); + } selected += 1; } @@ -72,8 +81,12 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - tune.playTone(pad, 261.63, 0.20); - playGame(lcd, pad, device, tune, _mazeIndex); // call the game function + wait_ms(100); + if (_tone){ + pad.tone(196.00, 0.20); + } + playGame(lcd, pad, device, animate, _mazeIndex, _tone, _FPS); + // call the game function } wait_ms(250); // 250ms propogation delay @@ -95,8 +108,11 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - tune.playTone(pad, 261.63, 0.20); - options(lcd, pad, animate); + wait_ms(250); + if (_tone){ + pad.tone(196.00, 0.20); + } + options(lcd, pad, animate, _tone); } wait_ms(250); // 250ms propogation delay @@ -118,8 +134,11 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - tune.playTone(pad, 261.63, 0.20); - lcdSettings(lcd, pad); + wait_ms(250); + if (_tone){ + pad.tone(196.00, 0.20); + } + lcdSettings(lcd, pad, animate); } wait_ms(250); // 250ms propogation delay @@ -141,8 +160,11 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - tune.playTone(pad, 261.63, 0.20); - soundSettings(lcd, pad); + wait_ms(250); + if (_tone){ + pad.tone(196.00, 0.20); + } + soundSettings(lcd, pad, animate); } wait_ms(250); // 250ms propogation delay @@ -163,12 +185,12 @@ } /// INTRO LOOP /// -void Menu::intro(N5110 &lcd, Gamepad &pad, Sound &tune, Animations &animate) +void Menu::intro(N5110 &lcd, Gamepad &pad, Animations &animate) { // printf("intro started \n"); while (pad.check_event(Gamepad::START_PRESSED) == false){ - animate.intro(lcd, pad, tune); + animate.intro(lcd, pad); } } @@ -176,38 +198,54 @@ void Menu::playGame(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, - Sound &tune, - int mazeIndex) + Animations &animate, + int mazeIndex, + bool tone, + float FPS) { - int exit = 0; - int x; int y; int radius; - _mazeIndex = mazeIndex; + int _mazeIndex = randomMazeIndexGenerator(mazeIndex); + // generates random number for maze index between different + // pairs of values with corresponding difficulties + _FPS = FPS; - if (_mazeIndex == 0) { + if (_mazeIndex < 3) { - x = 40; // place ball in start of screen approx. - y = 20; - radius = 4; - } - - else if (_mazeIndex == 1){ - - x = 3; - y = 3; + x = 5; // place ball in start of screen approx. + y = 5; radius = 2; } - else if (_mazeIndex == 2){ + else if ((_mazeIndex == 3) || + (_mazeIndex == 4) || + (_mazeIndex == 5)){ x = 4; y = 3; radius = 1; } + else if ((_mazeIndex == 6) || + (_mazeIndex == 7) || + (_mazeIndex == 8)){ + + x = 3; + y = 4; + radius = 0; + } + + else { + + x = 2; + y = 2; + radius = 0; + } + + + _engine.init(_mazeIndex, // selects maze difficulty x, // defines starting x position for ball y, // defines starting y position for ball @@ -215,15 +253,103 @@ _control, // control method _colour); // type of ball + printGameParameters(_mazeIndex, + x, + y, + radius, + _control, + _colour, + _FPS); // prints all game settings to serial port + + int exit = 0; + while (exit == 0){ + + _engine._goal = false; + + // rendering screen + lcd.clear(); + _engine.draw(lcd); + lcd.refresh(); + + _engine.readInput(pad, device); + _engine.update(lcd); + + wait_ms(_FPS); + + if (_engine.checkGoal(lcd)){ + + animateStickman(lcd, pad, animate); + exit ++; + } + + // get direction of the joystick + char d = pad.get_direction(); + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit++; + } + } +} + +int Menu::randomMazeIndexGenerator(int mazeIndex) +{ + /// rand() % (max - min+1) + min /// + + _mazeIndex = mazeIndex; + + if (_mazeIndex < 3) { + + _mazeIndex = rand() % 3; // random number between 0 and 2 + } + + else if ((_mazeIndex == 3) || + (_mazeIndex == 4) || + (_mazeIndex == 5)){ + + _mazeIndex = rand() % 6 + 3; // random number between 3 and 5 + } + + else if ((_mazeIndex == 6) || + (_mazeIndex == 7) || + (_mazeIndex == 8)){ + + _mazeIndex = rand() % 9 + 6; // random number between 6 and 8 + } + + else { + + _mazeIndex = 9; // no random number as only one maze at this level + } + + return _mazeIndex; +} + +void Menu::printGameParameters(int mazeIndex, + int x, + int y, + int radius, + bool control, + bool colour, + float FPS) +{ + int _x = x; + int _y = y; + int _radius = radius; + bool _control = control; + bool _colour = colour; + float _fps = FPS; + // printf out all game parameters - printf("Game parameters: \nDifficulty = %i \n", _mazeIndex); - printf("Ball position = (%i, %i)\n", x, y); - printf("Ball radius = %i \n", radius); + printf("Game parameters: \nMaze Index = %i \n", _mazeIndex); + printf("Ball position = (%i, %i)\n", _x, _y); + printf("Ball radius = %i \n", _radius); + printf("Game speed = %f \n", _fps); + if (_colour){ - printf("Ball colour = black \n"); + printf("Ball colour: outline \n"); } if (!_colour){ - printf("Ball colour = transparent \n"); + printf("Ball colour: black \n"); } if (_control){ printf("Control method: Joystick \n"); @@ -231,33 +357,16 @@ if (!_control){ printf("Control method: Accelerometer \n"); } + printf("\n\n ---NEW LINE---\n\n"); - while (exit == 0){ - - _engine.readInput(pad, device); - _engine.update(pad, lcd); - - // rendering screen - lcd.clear(); - _engine.draw(lcd); - lcd.refresh(); - - wait_ms(100); - - // get direction of the joystick - char d = pad.get_direction(); - if (pad.check_event(Gamepad::BACK_PRESSED)){ - - exit++; - } - } } /// MENU FUNCTIONS /// -void Menu::options(N5110 &lcd, Gamepad &pad, Animations &animate) +void Menu::options(N5110 &lcd, Gamepad &pad, Animations &animate, bool tone) { int exit = 0; int selected = 0; + wait_ms(250); while(exit == 0) { @@ -290,16 +399,21 @@ lcd.printString(">Difficulty", 0, 2); lcd.printString(" Ball Colour", 0, 3); lcd.printString(" Control", 0, 4); + lcd.printString(" Game speed ", 0, 5); lcd.refresh(); + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { + if (_tone){ + pad.tone(196.00, 0.20); + } difficultyOptions(lcd, pad); } - wait_ms(250); break; @@ -311,17 +425,22 @@ lcd.printString(" Difficulty", 0, 2); lcd.printString(">Ball Colour", 0, 3); lcd.printString(" Control", 0, 4); + lcd.printString(" Game speed ", 0, 5); lcd.refresh(); + wait_ms(250); + // if second option selected if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - lcdColourOptions(lcd, pad); + if (_tone){ + pad.tone(196.00, 0.20); + } + ballColourOptions(lcd, pad, animate); } - wait_ms(250); break; @@ -333,20 +452,52 @@ lcd.printString(" Difficulty", 0, 2); lcd.printString(" Ball Colour", 0, 3); lcd.printString(">Control", 0, 4); + lcd.printString(" Game speed ", 0, 5); lcd.refresh(); + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { + if (_tone){ + pad.tone(196.00, 0.20); + } controlOptions(lcd, pad, animate); } + + break; + + case 4: + + lcd.clear(); + // displays options page with indicator on first + lcd.printString("Game Options:", 0, 0); + lcd.printString(" Difficulty", 0, 2); + lcd.printString(" Ball Colour", 0, 3); + lcd.printString(" Control", 0, 4); + lcd.printString(">Game speed ", 0, 5); + lcd.refresh(); + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)) || + (d == E)) { + + if (_tone){ + pad.tone(196.00, 0.20); + } + speedSettings(lcd, pad); + } + + break; + default: selected = 1; @@ -362,10 +513,11 @@ } } -void Menu::lcdSettings(N5110 &lcd, Gamepad &pad) +void Menu::lcdSettings(N5110 &lcd, Gamepad &pad, Animations &animate) { int exit = 0; int selected = 0; + wait_ms(250); while(exit == 0) { @@ -398,15 +550,18 @@ lcd.printString(" Invert Colour", 0, 3); lcd.refresh(); + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - lcdBackgroundColour(lcd, pad); + if (_tone){ + pad.tone(196.00, 0.20); + } + lcdBackgroundColour(lcd, pad, animate); } - wait_ms(250); - break; case 2: @@ -418,16 +573,19 @@ lcd.printString(">Invert Colour", 0, 3); lcd.refresh(); + wait_ms(250); + // if second option selected if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { + if (_tone){ + pad.tone(196.00, 0.20); + } lcdInverseColour(lcd, pad); } - wait_ms(250); - break; default: @@ -448,26 +606,21 @@ } -void Menu::soundSettings(N5110 &lcd, Gamepad &pad) +void Menu::soundSettings(N5110 &lcd, Gamepad &pad, Animations &animate) { int selected = 0; int exit = 0; - // pad.tone(750.0,0.1); while (exit == 0){ char d = pad.get_direction(); - if ((d == NW) || - (d == N) || - (d == NE)){ + if (d == E){ selected -= 1; } - if ((d == SW) || - (d == S) || - (d == SE)){ + if (d == W){ selected += 1; } @@ -480,15 +633,18 @@ lcd.clear(); // displays options page with indicator on first lcd.printString("Sound Settings", 0, 0); - lcd.printString(">Sound effects", 0, 2); - lcd.printString(" Music", 0, 3); + lcd.printString("Turn sound on", 0, 2); + animate.soundSwitch(lcd, _tone); lcd.refresh(); + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || - pad.check_event(Gamepad::JOY_PRESSED)) || - (d == E)) { + pad.check_event(Gamepad::JOY_PRESSED))) { - // soundEffects(lcd, pad); + _tone = true; + animate.soundSwitch(lcd, _tone); + pad.tone(261.63, 0.20); } wait_ms(250); @@ -498,18 +654,19 @@ case 2: lcd.clear(); - // displays options page with indicator on second + // displays options page with indicator on first lcd.printString("Sound Settings", 0, 0); - lcd.printString(" Sound effects", 0, 2); - lcd.printString(">Music", 0, 3); + lcd.printString("Turn sound off", 0, 2); + animate.soundSwitch(lcd, _tone); lcd.refresh(); - // if second option selected + wait_ms(250); + if ((pad.check_event(Gamepad::A_PRESSED) || - pad.check_event(Gamepad::JOY_PRESSED)) || - (d == E)) { + pad.check_event(Gamepad::JOY_PRESSED))) { - // soundEffects(lcd, pad); + _tone = false; + animate.soundSwitch(lcd, _tone); } wait_ms(250); @@ -537,6 +694,8 @@ int selected = 0; int exit = 0; + wait_ms(250); + while (exit == 0){ char d = pad.get_direction(); @@ -549,21 +708,56 @@ if (d == E){ selected++; - } switch(selected){ case 1: - animateJoystick(lcd, pad, animate); + lcd.clear(); + lcd.printString("Control: ", 0, 0); + lcd.printString(" Joystick ", 0, 2); + lcd.printString(" >", 0, 3); + animate.drawVerticalJoystick(lcd); + lcd.refresh(); + + wait_ms(250); + + if (pad.check_event(Gamepad::A_PRESSED)|| + pad.check_event(Gamepad::JOY_PRESSED)){ + + _control = true; + animateJoystick(lcd, animate); + if (_tone){ + pad.tone(196.00, 0.20); + } + exit++; + } break; case 2: - animateGamepad(lcd, pad, animate); + lcd.clear(); + lcd.printString("Control: ", 0, 0); + lcd.printString(" Gamepad ", 0, 2); + lcd.printString("< ", 0, 3); + animate.drawVerticalGamepad(lcd); + lcd.refresh(); + + wait_ms(250); + + if (pad.check_event(Gamepad::A_PRESSED)|| + pad.check_event(Gamepad::JOY_PRESSED)){ + + _control = false; + animateGamepad(lcd, animate); + if (_tone){ + pad.tone(196.00, 0.20); + } + exit++; + } break; @@ -588,6 +782,7 @@ { int selected = 0; int exit = 0; + wait_ms(250); while(exit == 0){ @@ -625,10 +820,15 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _mazeIndex = 0; + _mazeIndex = 1; + + if (_tone){ + pad.tone(196.00, 0.20); + } lcd.clear(); - lcd.printString("Easy mode", 0, 1); + lcd.printString(" EASY", 0, 1); + lcd.printString(" MODE", 0, 2); lcd.refresh(); wait(2); @@ -647,18 +847,21 @@ lcd.printString(" Extreme", 0, 5); lcd.refresh(); - wait_ms(250); // 250ms propogation delay if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _mazeIndex = 1; + _mazeIndex = 3; - // maze.mazeIndex = 1; + if (_tone){ + pad.tone(196.00, 0.20); + } + lcd.clear(); - lcd.printString("Medium mode", 0, 1); + lcd.printString(" MEDIUM", 0, 1); + lcd.printString(" MODE", 0, 2); lcd.refresh(); wait(2); @@ -673,21 +876,25 @@ lcd.printString("Difficulty: ", 0, 0); lcd.printString(" Easy", 0, 2); lcd.printString(" Medium", 0, 3); - lcd.printString(">Hard", 0, 4); - lcd.printString(" Extreme", 0, 5); + lcd.printString(">Hard ", 0, 4); + lcd.printString(" Extreme ", 0, 5); lcd.refresh(); - wait_ms(250); // 250ms propogation delay if ((pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _mazeIndex = 3; + _mazeIndex = 6; + + if (_tone){ + pad.tone(196.00, 0.20); + } lcd.clear(); - lcd.printString("Hard mode", 0, 1); + lcd.printString(" HARD", 0, 1); + lcd.printString(" MODE", 0, 2); lcd.refresh(); wait(2); @@ -699,11 +906,10 @@ case 4: lcd.clear(); - lcd.printString("Difficulty: ", 0, 0); - lcd.printString(" Easy", 0, 2); - lcd.printString(" Medium", 0, 3); - lcd.printString(" Hard", 0, 4); - lcd.printString(">Extreme", 0, 5); + lcd.printString(" Easy", 0, 1); + lcd.printString(" Medium", 0, 2); + lcd.printString(" Hard", 0, 3); + lcd.printString(">Extreme", 0, 4); lcd.refresh(); @@ -713,10 +919,15 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _mazeIndex = 4; + _mazeIndex = 9; + + if (_tone){ + pad.tone(196.00, 0.20); + } lcd.clear(); - lcd.printString("Extreme mode", 0, 1); + lcd.printString(" EXTREME ", 0, 1); + lcd.printString(" MODE", 0, 2); lcd.refresh(); wait(2); @@ -724,8 +935,6 @@ } break; - - default: @@ -740,16 +949,14 @@ exit++; } - } - - } -void Menu::lcdColourOptions(N5110 &lcd, Gamepad &pad) +void Menu::ballColourOptions(N5110 &lcd, Gamepad &pad, Animations &animate) { int selected = 0; int exit = 0; + wait_ms(250); while(exit == 0){ @@ -787,21 +994,12 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _colour = true; - - // shows ball rolling across the screen - for (int i = 0; i < 100; i++){ - - lcd.clear(); - lcd.printString(" Outline ", 0, 1); - lcd.drawCircle(i, 32, 8, FILL_TRANSPARENT); - lcd.refresh(); - wait_ms(40); - + if (_tone){ + pad.tone(196.00, 0.20); } - // wait(2); - + _colour = true; // true colour => outline + animate.rollingEmptyBall(lcd); exit++; } @@ -824,23 +1022,15 @@ pad.check_event(Gamepad::JOY_PRESSED)) || (d == E)) { - _colour = false; + if (_tone){ + pad.tone(196.00, 0.20); + } - // shows ball rolling across the screen - for (int i = 0; i < 100; i++){ - - lcd.clear(); - lcd.printString(" Solid ", 0, 1); - lcd.drawCircle(i, 32, 8, FILL_BLACK); - lcd.refresh(); - wait_ms(40); - - - } + _colour = false; // false colour => solid + animate.rollingSolidBall(lcd); + exit++; } - exit++; - break; default: @@ -876,6 +1066,9 @@ if (pad.check_event(Gamepad::A_PRESSED)){ lcd.inverseMode(); + if (_tone){ + pad.tone(196.00, 0.20); + } } @@ -883,6 +1076,9 @@ lcd.normalMode(); + if (_tone){ + pad.tone(196.00, 0.20); + } } lcd.refresh(); @@ -899,7 +1095,7 @@ } -void Menu::lcdBackgroundColour(N5110 &lcd, Gamepad &pad) +void Menu::lcdBackgroundColour(N5110 &lcd, Gamepad &pad, Animations &animate) { // method to change the brightness of the LED backlight int exit = 0; @@ -914,15 +1110,62 @@ double brightness = pad.read_pot(); // returns value between 0.0 - 1.0 lcd.setBrightness(brightness); - lcd.refresh(); - - int width = brightness * 40; lcd.drawRect(10, 30, 41, 8, FILL_TRANSPARENT); - lcd.drawRect(11, 31, width, 6, FILL_BLACK); + lcd.drawRect(11, 31, brightness * 40, 6, FILL_BLACK); + lcd.refresh(); + + // animate.brightnessBar(lcd, brightness); lcd.refresh(); - wait_ms(10); + wait_ms(5); + + char d = pad.get_direction(); + + if ((pad.check_event(Gamepad::BACK_PRESSED)) || + (d == W)){ + + exit++; + } + } +} + +void Menu::speedSettings(N5110 &lcd, Gamepad &pad) +{ + int exit = 0; + + while (exit == 0){ + + lcd.clear(); + lcd.printString("Use dial to ", 0, 0); + lcd.printString("adjust speed", 0, 1); + + double speed = pad.read_pot(); // returns value between 0.0 - 1.0 + + // nominal value is 50 FPS, i.e speed of 0.5 + // have values between 25 and 75 + + // pot value of 0 corresponds to FPS of 25 + // pot value of 1 cooresponds to FPS of 75 + + // relationship between pot value and FPS: + _FPS = (speed * 50) + 25; + + // lcd.drawRect(10, 30, 41, 8, FILL_TRANSPARENT); + // lcd.drawRect(11, 31, _FPS, 6, FILL_BLACK); + + lcd.drawCircle(42, 31, 12, FILL_TRANSPARENT); + + // printf("input = %f \n", input); + + double x2 = 42 + (12 * sin(1.5 * 3.14159 * (speed - 0.5))); + double y2 = 31 - (12 * cos(1.5 * 3.14159 * (speed - 0.5))); + + lcd.drawLine(42, 31, x2, y2, FILL_BLACK); + + lcd.refresh(); + + wait_ms(5); char d = pad.get_direction(); @@ -934,287 +1177,165 @@ } } -void Menu::animateJoystick(N5110 &lcd, Gamepad &pad, Animations &animate) +void Menu::animateJoystick(N5110 &lcd, Animations &animate) { - int exit = 0; - - while (exit == 0){ - - char d = pad.get_direction(); - - lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Joystick ", 0, 2); - lcd.printString(" >", 0, 3); - animate.drawLeftJoystick(lcd); - lcd.refresh(); - lcd.clear(); - wait_ms(500); - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = true; - - lcd.clear(); - lcd.printString(" JOYSTICK ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == E){ - - exit++; - } - - lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Joystick ", 0, 2); - lcd.printString(" >", 0, 3); - animate.drawVerticalJoystick(lcd); - lcd.refresh(); - wait_ms(500); - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = true; - - lcd.clear(); - lcd.printString(" JOYSTICK ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == E){ - - exit++; - } + int timer = 0; + while (timer <= 3200){ lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Joystick ", 0, 2); - lcd.printString(" >", 0, 3); - animate.drawRightJoystick(lcd); - lcd.refresh(); - wait_ms(500); - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = true; - - lcd.clear(); - lcd.printString(" JOYSTICK ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == E){ - - exit++; - } - - - lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Joystick ", 0, 2); - lcd.printString(" >", 0, 3); - animate.drawVerticalJoystick(lcd); + lcd.printString(" JOYSTICK ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawLeftJoystick(lcd); lcd.refresh(); - wait_ms(500); - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = true; - - lcd.clear(); - lcd.printString(" JOYSTICK ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == E){ - - return; - } - } -} - -void Menu::animateGamepad(N5110 &lcd, Gamepad &pad, Animations &animate) -{ - int exit = 0; - - while (exit == 0){ - - char d = pad.get_direction(); - - if (d == W){ - - exit++; - } + timer += 400; + wait_ms(400); lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Gamepad ", 0, 2); - lcd.printString("< ", 0, 3); - animate.drawLeftGamepad(lcd); + lcd.printString(" JOYSTICK ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawVerticalJoystick(lcd); lcd.refresh(); - lcd.clear(); - wait_ms(500); - - if (d == W){ - - exit++; - } - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = false; - - lcd.clear(); - lcd.printString(" TILT ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(2); - - return; - } - - if (d == W){ - - exit++; - } + timer += 400; + wait_ms(400); lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Gamepad ", 0, 2); - lcd.printString("< ", 0, 3); - animate.drawVerticalGamepad(lcd); + lcd.printString(" JOYSTICK ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawRightJoystick(lcd); lcd.refresh(); - wait_ms(500); - - if (d == W){ - - exit++; - } - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = false; - - lcd.clear(); - lcd.printString(" TILT ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == W){ - - exit++; - } - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = false; - - lcd.clear(); - lcd.printString(" TILT ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == W){ - - exit++; - } + timer += 400; + wait_ms(400); lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Gamepad ", 0, 2); - lcd.printString("< ", 0, 3); - animate.drawRightGamepad(lcd); + lcd.printString(" JOYSTICK ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawVerticalJoystick(lcd); lcd.refresh(); - wait_ms(500); - - if (d == W){ - - exit++; - } - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = false; - - lcd.clear(); - lcd.printString(" TILT ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == W){ - - exit++; - } - - lcd.clear(); - lcd.printString("Control: ", 0, 0); - lcd.printString(" Gamepad ", 0, 2); - lcd.printString("< ", 0, 3); - animate.drawVerticalGamepad(lcd); - lcd.refresh(); - wait_ms(500); - - if (d == W){ - - exit++; - } - - if (pad.check_event(Gamepad::A_PRESSED)|| - pad.check_event(Gamepad::JOY_PRESSED)){ - - _control = false; - - lcd.clear(); - lcd.printString(" TILT ", 0, 1); - lcd.printString(" SELECTED ", 0, 2); - lcd.refresh(); - wait(1); - - return; - } - - if (d == W){ - - exit++; - } + timer += 400; + wait_ms(400); } } +void Menu::animateGamepad(N5110 &lcd, Animations &animate) +{ + int timer = 0; + while (timer <= 3200){ + + lcd.clear(); + lcd.printString(" GAMEPAD TILT ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawLeftGamepad(lcd); + lcd.refresh(); + timer += 400; + wait_ms(400); + + lcd.clear(); + lcd.printString(" GAMEPAD TILT ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawVerticalGamepad(lcd); + lcd.refresh(); + timer += 400; + wait_ms(400); + + + lcd.clear(); + lcd.printString(" GAMEPAD TILT ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawRightGamepad(lcd); + lcd.refresh(); + timer += 400; + wait_ms(400); + + lcd.clear(); + lcd.printString(" GAMEPAD TILT ", 0, 1); + lcd.printString(" SELECTED ", 0, 2); + animate.drawVerticalGamepad(lcd); + lcd.refresh(); + timer += 400; + wait_ms(400); + } +} + +void Menu::animateStickman(N5110 &lcd, Gamepad &pad, Animations &animate) +{ + int timer = 0; + while (timer <= 3200){ + + int delay = 60; + + lcd.clear(); + animate.stickmanOne(lcd); + pad.leds_on(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanTwo(lcd); + pad.leds_off(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanThree(lcd); + pad.leds_on(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanFour(lcd); + pad.leds_off(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanFive(lcd); + pad.leds_on(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanSix(lcd); + pad.leds_off(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanFive(lcd); + pad.leds_on(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanFour(lcd); + pad.leds_off(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanThree(lcd); + pad.leds_on(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + lcd.clear(); + animate.stickmanTwo(lcd); + pad.leds_off(); + lcd.refresh(); + timer += delay; + wait_ms(delay); + + } + +} + +