ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

tutorial/tutorial.cpp

Committer:
Noximilien
Date:
2019-04-02
Revision:
24:0570cb4b92d7
Child:
27:f05f4e738ba9

File content as of revision 24:0570cb4b92d7:

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


const int total_pages = 3;
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("Also. ",0,1);
    lcd.printString("Kill the ",5,2);
    lcd.printString("Enemies!!! ",10,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)){
        back_to_menu = true; 
    }
    return back_to_menu;   
        
}