James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pause.cpp Source File

Pause.cpp

00001 #include "Pause.h"
00002 
00003 //constructor
00004 Pause::Pause(){
00005 }
00006 
00007 //destructor
00008 Pause::~Pause(){
00009 }
00010 
00011 ////initialiser
00012 void Pause::init(){
00013     _state = RESUME;        //set arrows to point to first item in the menu
00014 }
00015 
00016 PauseOption Pause::pause_menu(Gamepad &gamepad, N5110 &lcd, int fps){
00017     PauseOption choice = RESUME;        //choice stores the state to be selected and pointed to with arrows
00018     while(!(gamepad.check_event(gamepad.A_PRESSED))){   //check for user selection
00019         lcd.clear();
00020         display_pause_options(lcd);         //render the menu on the screen
00021         choice = pause_selection(gamepad, lcd);     //update currently selected choice and point to it with arrows
00022         lcd.refresh();
00023         wait(0.2);      //avoid button bounce as much as poss
00024     }
00025     return choice;
00026 }
00027 
00028 
00029 
00030 int Pause::brickbreaker_action(PauseOption choice, Gamepad &gamepad, N5110 &lcd, int frame, int fps){    
00031     int jump_to_frame = frame;
00032     if(choice == RESUME){ jump_to_frame = frame; }              //Just keep code iterating
00033     if(choice == RESTART){ jump_to_frame = 0; }                 //return to frame 1 if restarted
00034     if(choice == QUIT){ jump_to_frame = 45*fps; }               //jump to final frame
00035     if(choice == HELP){ brickbreaker_help(gamepad, lcd); }      //display relevant help screen
00036     return jump_to_frame;                       
00037 }
00038 
00039 
00040 void Pause::display_pause_options(N5110 &lcd){
00041     lcd.printString("GAME PAUSED:", 6, 0);      //text for each line of the display
00042     lcd.printString("Resume", 24, 1);
00043     lcd.printString("Restart", 21, 2);
00044     lcd.printString("Quit", 30, 3);
00045     lcd.printString("Help", 30, 4);
00046     lcd.printString("(Select = A)", 6, 5);
00047 }
00048 
00049 PauseOption Pause::pause_selection(Gamepad &gamepad, N5110 &lcd){
00050     PauseSelection fsm[4] = {       //state machine to power the pause menu
00051         {1,{HELP,RESTART,RESUME}},      //output (1,2,3 or 4) is the line to print the arrows on
00052         {2,{RESUME,QUIT,RESTART}},      //next_state[0] is the option above the current item
00053         {3,{RESTART,HELP,QUIT}},        //next_state[1] is the option below the current item
00054         {4,{QUIT,RESUME,HELP}}          //next_state[2] is the current item/state
00055     };
00056     if(gamepad.get_direction() == N){ _next_state = 0;}         //move up
00057     else if(gamepad.get_direction() == S){ _next_state = 1;}        //move down
00058     else{ _next_state = 2;}         //arrows in same position (default)
00059     _state = fsm[_state].next_state[_next_state];       //update state
00060     lcd.printString(">", 6, fsm[_state].output);        //print arrows to LCD display
00061     lcd.printString("<", 72, fsm[_state].output);
00062     return _state;
00063 }
00064 
00065 void Pause::classic_help(Gamepad &gamepad, N5110 &lcd){
00066     while(!(gamepad.check_event(gamepad.A_PRESSED))){       //check for user advancing
00067         lcd.clear();
00068         lcd.printString("Help", 30, 0);             //display each line of help 
00069         lcd.printString("Don't leave", 0, 1);       //on LCD display
00070         lcd.printString("the path! Tilt", 0, 2);
00071         lcd.printString("pad to roll", 0, 3);
00072         lcd.printString("the ball", 0, 4);
00073         lcd.printString("(Press A)", 0, 5);
00074         lcd.refresh();
00075         wait(0.5);
00076     }
00077 }
00078 
00079 void Pause::brickbreaker_help(Gamepad &gamepad, N5110 &lcd){
00080     while(!(gamepad.check_event(gamepad.A_PRESSED))){       //check for user advancing
00081         lcd.clear();
00082         lcd.printString("Help", 30, 0);                 //display each line of help
00083         lcd.printString("Tilt gamepad", 0, 1);          //on LCD display
00084         lcd.printString("to move ball", 0, 2);
00085         lcd.printString("Game length=", 0, 3);
00086         lcd.printString("45 secs", 0, 4);
00087         lcd.printString("(Press A)", 0, 5);
00088         lcd.refresh();
00089         wait(0.5);
00090     }
00091 }