Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
29:579e00b7f118
Parent:
28:35af3843de8f
Child:
30:d454d0cb72bc
--- a/tutorial/tutorial.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/tutorial/tutorial.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -3,21 +3,58 @@
 #include "tutorial.h"
 #include "constants.h"
 #include "models.h"
+#include "gameobject.h"
 
 
-const int total_pages = 7;
-const float time_delay = 100;
 
 Tutorial::Tutorial() {                              
     current_page = 0;                     
 }                                          
 
+GameObject arrowLeft;
+GameObject arrowRight;
+
 /**@brief
   * This function just displays some strings of the dysplaye to tell the player
   * how to use the controls and what to do.
   */
 bool Tutorial::updateAndWriteTutorial(){
-    if(x_dir.read() > joy_threshold_max_x){
+    turnPages();
+    drawArrowsAndExitButton();
+    
+    if (current_page == 0){ tutorialPage0();}
+    else if (current_page == 1){ tutorialPage1();}
+    else if (current_page == 2){ tutorialPage2();}
+    else if (current_page == 3){ tutorialPage3();}
+    else if (current_page == 4){ tutorialPage4();}
+    else if (current_page == 5){ tutorialPage5();}
+    else if (current_page == 6){ tutorialPage6();}
+    
+    bool back_to_menu = false;    
+    if (gamepad.check_event(gamepad.B_PRESSED)){
+        gamepad.check_event(gamepad.B_PRESSED);
+        back_to_menu = true; 
+    }
+    return back_to_menu;   
+}
+
+void Tutorial::drawArrowsAndExitButton(){
+    char buffer[16];
+    sprintf(buffer,"page #%i", current_page);
+    lcd.printString(buffer,20,0);
+    
+    arrowLeft.pos.x = left_arrow_pos_x;
+    arrowLeft.pos.y = arrows_pos_y;
+    arrowRight.pos.x = right_arrow_pos_x;
+    arrowRight.pos.y = arrows_pos_y;
+  
+    drawSprite(arrowRight.pos, tutorial_arrow_right_sprite);
+    drawSprite(arrowLeft.pos, tutorial_arrow_left_sprite);
+    lcd.printString("Push B to Exit",0,5);
+}
+
+void Tutorial::turnPages(){
+     if(x_dir.read() > joy_threshold_max_x){
         current_page -= 1;
         wait_ms(time_delay);    
     } 
@@ -30,68 +67,49 @@
     }
     if (current_page >= total_pages) {
         current_page -= total_pages;
-    }
-    
-    
-    bool back_to_menu = false;
-    
-    if (current_page == 0){
+    }  
+}
+
+void Tutorial::tutorialPage0(){
     lcd.printString("X - shoot",0,1);
     lcd.printString("START - Pause",0,2);
     lcd.printString("JOYSTICK - is ",0,3);
     lcd.printString("ship movement",0,4);
-    }
-    
-    else if (current_page == 1){
+}
+
+void Tutorial::tutorialPage1(){
     lcd.printString("Evade enemy ",0,1);
     lcd.printString("shots and",0,2);
     lcd.printString("don't let ",0,3);
-    lcd.printString("them pass.",0,4);   
-    }
-    
-    else if (current_page == 2){
+    lcd.printString("them pass.",0,4);
+}
+
+void Tutorial::tutorialPage2(){
     lcd.printString("Your health is",0,1);
     lcd.printString("shown below",0,2);
     lcd.printString("the screen ",0,3);
-    lcd.printString("Its LEDs. ",0,4);
-    }
-    
-    else if (current_page == 3){
-    lcd.printString("Also. ",0,1);
+    lcd.printString("It's LEDs. ",0,4);
+}
+
+void Tutorial::tutorialPage3(){
     lcd.printString("Kill the ",5,2);
     lcd.printString("Enemies!!! ",10,3);
-    }
-    
-    else if (current_page == 4){
+}
+
+void Tutorial::tutorialPage4(){
     lcd.printString("foe died= 30",0,1);
     lcd.printString("miss shot= -10",0,2);
     lcd.printString("foe left= -50",0,3);
     lcd.printString("Be careful ",10,4);
-    }
-    
-    else if (current_page == 5){
+}
+
+void Tutorial::tutorialPage5(){
     lcd.printString("As your score",0,1);
     lcd.printString("increase, so ",0,2);
     lcd.printString("does the game ",0,3);
     lcd.printString("difficulty ",10,4);
-    }
-    
-    else if (current_page == 6){
+}
+
+void Tutorial::tutorialPage6(){
     lcd.printString("Good Luck!!! ",0,3);
-    }
-    
-    char buffer[1];
-    sprintf(buffer,"page #%i", current_page);
-    lcd.printString(buffer,20,0);  
-    
-    lcd.drawSpriteOnTop(right_arrow_pos_x, arrows_pos_y, 7, 10, (int *)tutorialArrowRight);
-    lcd.drawSpriteOnTop(left_arrow_pos_x, arrows_pos_y, 7, 10, (int *)tutorialArrowLeft);
-    lcd.printString("Push B to Exit",0,5);
-    
-    if (gamepad.check_event(gamepad.B_PRESSED)){
-        gamepad.check_event(gamepad.B_PRESSED);
-        back_to_menu = true; 
-    }
-    return back_to_menu;   
-        
-}   
\ No newline at end of file
+}
\ No newline at end of file