Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: MenuClasses/Tutorial/Tutorial.cpp
- Revision:
- 80:51ca38c5dcdf
- Parent:
- 78:10e5cc013806
- Child:
- 83:329da564799a
diff -r 35cb65c52d25 -r 51ca38c5dcdf MenuClasses/Tutorial/Tutorial.cpp --- a/MenuClasses/Tutorial/Tutorial.cpp Sun May 05 23:48:57 2019 +0000 +++ b/MenuClasses/Tutorial/Tutorial.cpp Mon May 06 08:00:56 2019 +0000 @@ -24,14 +24,14 @@ {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}, {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0}, + {0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0}, {0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0}, {0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0}, {0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,1,0}, {1,0,0,0,0,0,0,1,0,0,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,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}, @@ -194,16 +194,46 @@ {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0}, }; +int Back[9][19] = { + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,0,1,0,0,0,1,1,0,1,0,1,0,1}, + {1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,1,0,0,1}, + {1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,0,0,0,1}, + {1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,1,0,0,1}, + {1,0,1,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, +}; void Tutorial::Implement(N5110 &lcd, Gamepad &pad) { - //pad.init(); - Tutorial::gamePad(lcd, pad); - Tutorial::settings(lcd, pad); - Tutorial::controlsToNavigateInMenu(lcd, pad); - Tutorial::controlsToNavigateGameModeSpeed(lcd,pad); - Tutorial::controlsToPlayGame(lcd, pad); - Tutorial::controlsForPreviousOrNext(lcd, pad); + //Only executed if back is not pressed. Takes us to tutorial of how to navigate through the tutorial. + if(_backPressed == false) { Tutorial::gamePad(lcd, pad); } + //Only executed if back is not pressed. Takes us to tutorial of how to operate settings. + if(_backPressed == false) { Tutorial::settings(lcd, pad); } + //Only executed if back is not pressed. Takes us to tutorial of how to navigate through main menu. + if(_backPressed == false) { Tutorial::controlsToNavigateInMenu(lcd, pad); } + //Only executed if back is not pressed. Takes us to tutorial of how to navigate through mode and speed menu. + if(_backPressed == false) { Tutorial::controlsToNavigateGameModeSpeed(lcd,pad); } + //Only executed if back is not pressed. Takes us to tutorial of how to use in game controls and how to move snake. + if(_backPressed == false) { Tutorial::controlsToPlayGame(lcd, pad); } + //Only executed if back is not pressed. Takes us to tutorial of how to navigate back and forth in menus & start or end a game.. + if(_backPressed == false) { Tutorial::controlsForPreviousOrNext(lcd, pad); } + //RESETS _backPressed, for displaying all the tutorials if it has been selected once again in main menu. + _backPressed = false; +} + +bool Tutorial::checkBackPressed(Gamepad &pad) +{ + //This is a very important process, this helps the code to not get stuck in menu loop but also allow to toggle between diffrent menu screens. + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { + pad.tone(1000.0,0.1); + _backPressed = true; + } else { + _backPressed = false; + } + return _backPressed; //returns true if back is pressed, returns false otherwise. } void Tutorial::gamePad(N5110 &lcd, Gamepad &pad) @@ -211,9 +241,12 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)g_pad); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Press Start or",0,4); lcd.printString("A to proceed",7,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.25); pad.tone(1000.0,0.1); @@ -224,9 +257,12 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)Pot); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Rotate pot",12,4); lcd.printString("in settings",9,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.25); pad.tone(1000.0,0.1); @@ -237,9 +273,12 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)UpDown); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Up/Down",21,4); lcd.printString("for Main Menu",3,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.25); pad.tone(1000.0,0.1); @@ -250,9 +289,12 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)LeftRight); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Left/Right for",0,4); lcd.printString("Mode & Speed",7,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.3); pad.tone(1000.0,0.1); @@ -263,19 +305,25 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("InGameControls",0,4); - lcd.printString("to moove snake",0,5); + lcd.printString("to move snake",4,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.25); pad.tone(1000.0,0.1); - + lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Depends on",12,4); lcd.printString("mode selection",0,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.25); pad.tone(1000.0,0.1); @@ -286,19 +334,25 @@ lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Previous/Next",4,4); lcd.printString("End/Start",16,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.3); pad.tone(1000.0,0.1); - + lcd.clear(); while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { //if button pressed. lcd.drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite. + lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite. lcd.printString("Works in both",5,4); lcd.printString("menu and game",5,5); lcd.refresh(); + + if (Tutorial::checkBackPressed(pad)) { return; } //if back is pressed, the function is terminated. } wait(0.3); pad.tone(1000.0,0.1);