
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
Diff: main.cpp
- Revision:
- 18:100e7d3509b5
- Parent:
- 17:2fbe40177b9c
- Child:
- 19:074443a8c89b
--- a/main.cpp Fri May 22 01:46:19 2020 +0000 +++ b/main.cpp Fri May 22 22:10:15 2020 +0000 @@ -11,68 +11,16 @@ #include "Ball.h" #include "Splash.h" #include "Game.h" +#include "Instructions.h" +#include "Sprites.h" -const int highscore_icon [9][15] = { - {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, - {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, - {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, - {1,1,1,1,0,1,0,0,0,1,0,0,0,0,0}, - {1,0,0,1,0,1,0,0,0,1,0,1,1,1,1}, - {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, - {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, - {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, - {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, -}; -const int a_button [9][9] = { - {0,0,0,1,1,1,0,0,0}, - {0,0,1,0,0,0,1,0,0}, - {0,1,0,0,1,0,0,1,0}, - {1,0,0,1,0,1,0,0,1}, - {1,0,0,1,1,1,0,0,1}, - {1,0,0,1,0,1,0,0,1}, - {0,1,0,0,0,0,0,1,0}, - {0,0,1,0,0,0,1,0,0}, - {0,0,0,1,1,1,0,0,0} -}; -const int b_button [9][9] = { - {0,0,0,1,1,1,0,0,0}, - {0,0,1,0,0,0,1,0,0}, - {0,1,0,1,1,1,0,1,0}, - {1,0,0,1,0,0,1,0,1}, - {1,0,0,1,1,1,0,0,1}, - {1,0,0,1,0,0,1,0,1}, - {0,1,0,1,1,1,0,1,0}, - {0,0,1,0,0,0,1,0,0}, - {0,0,0,1,1,1,0,0,0} -}; -const int x_button [9][9] = { - {0,0,0,1,1,1,0,0,0}, - {0,0,1,0,0,0,1,0,0}, - {0,1,0,0,0,0,0,1,0}, - {1,0,0,1,0,1,0,0,1}, - {1,0,0,0,1,0,0,0,1}, - {1,0,0,1,0,1,0,0,1}, - {0,1,0,0,0,0,0,1,0}, - {0,0,1,0,0,0,1,0,0}, - {0,0,0,1,1,1,0,0,0} -}; -const int y_button [9][9] = { - {0,0,0,1,1,1,0,0,0}, - {0,0,1,0,0,0,1,0,0}, - {0,1,0,0,0,0,0,1,0}, - {1,0,0,1,0,1,0,0,1}, - {1,0,0,0,1,0,0,0,1}, - {1,0,0,0,1,0,0,0,1}, - {0,1,0,0,1,0,0,1,0}, - {0,0,1,0,0,0,1,0,0}, - {0,0,0,1,1,1,0,0,0} -}; //objects Gamepad pad; N5110 lcd; Ball ball(lcd); Splash splash(lcd, ball); Game game(lcd, pad, ball); +Instructions instruction(lcd, pad, ball, game); //functions void init(); void display_menu(); @@ -80,33 +28,26 @@ void how_to(); void display_settings(); //variables - +int page = 1; -int main() -{ +int main() { init(); - while (1) - { + while (1) { //ball.level_loop(); display_menu(); + page = 1; if (pad.A_pressed()) { game_loop(); - } - else if (pad.B_pressed()) { + } else if (pad.B_pressed()) { wait(0.2); //debounce - while(!pad.B_pressed()) { - //Instructions Page - wait_ms(100); - lcd.refresh(); - lcd.clear(); - } - } - else if (pad.X_pressed()) { + while(!pad.B_pressed()) {how_to();} + pad.reset_buttons(); + wait(0.2); + } else if (pad.X_pressed()) { while(!pad.B_pressed()) { display_settings(); } - } - else if (pad.Y_pressed()) { + } else if (pad.Y_pressed()) { lcd.turnOff(); pad.leds(0.0); } @@ -117,11 +58,10 @@ lcd.setContrast(0.5); pad.init(); lcd.backLightOn(); - //splash.displayInfo(); - //splash.playIntro(); + splash.displayInfo(); + splash.playIntro(); } -void display_menu() -{ +void display_menu() { splash.drawLogo(13, 0); lcd.printString("Play", 2, 2); lcd.printString("How-To?", 2, 3); @@ -153,11 +93,16 @@ pad.reset_buttons(); //to ensure no accidental selection on menu } void how_to() { - //page 1 - b to exit, buttons on gamepad - //page 2 - a to stop pointer, b to set power - //page 3- tips - //page 4- tips - //page 5- life after 5 points + if(pad.get_direction() == N) { + page--; + } else if (pad.get_direction() == S || page == 3 || page == 4) { + page++; + } + if(page > 7) {page = 7;} + if(page < 1) {page = 1;} + instruction.set_page(page); + instruction.display(); + wait(0.2); } void display_settings() { lcd.printString("Settings",20,0);