Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

tutorial/tutorial.cpp

Committer:
Noximilien
Date:
2019-04-08
Revision:
27:f05f4e738ba9
Parent:
24:0570cb4b92d7
Child:
28:35af3843de8f

File content as of revision 27:f05f4e738ba9:

#include "main.h"
#include "menu.h"
#include "tutorial.h"
#include "constants.h"
#include "models.h"


const int total_pages = 7;
const float time_delay = 100;

Tutorial::Tutorial() {                              
    current_page = 0;                     
}                                          

/**@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){
        current_page -= 1;
        wait_ms(time_delay);    
    } 
    else if (x_dir.read() < joy_threshold_min_x){
        current_page += 1;
        wait_ms(time_delay); 
    }
    if (current_page < 0) {
        current_page += total_pages;
    }
    if (current_page >= total_pages) {
        current_page -= total_pages;
    }
    
    
    bool back_to_menu = false;
    
    if (current_page == 0){
    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){
    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("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("Kill the ",5,2);
    lcd.printString("Enemies!!! ",10,3);
    }
    
    else if (current_page == 4){
    lcd.printString("foe died= 30",0,1);
    lcd.printString("miss shot= -10",0,2);
    lcd.printString("foe flew= -50",0,3);
    lcd.printString("Be careful ",10,4);
    }
    
    else if (current_page == 5){
    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){
    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;   
        
}