![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 31:bf765e3961f1
- Parent:
- 29:b2f63d8c1268
- Child:
- 34:911d7d05a8d2
diff -r 0af90779e141 -r bf765e3961f1 main.cpp --- a/main.cpp Thu Apr 25 08:08:30 2019 +0000 +++ b/main.cpp Fri Apr 26 09:12:03 2019 +0000 @@ -15,29 +15,31 @@ volatile int timer_flag = 0; void timer_isr(); +void init(); void main_menu(N5110 &lcd, Gamepad &pad); void print_main_menu(N5110 &lcd); int user_input(Gamepad &pad); -void select_menu_item(N5110 &lcd, Gamepad &pad, int input); +void select_main_menu_item(N5110 &lcd, Gamepad &pad, int input); + void menu_playgame(N5110 &lcd, Gamepad &pad); void menu_setcontrast(N5110 &lcd, Gamepad &pad); +void select_continue_menu_item(N5110 &lcd, Gamepad &pad, int input); +void print_continue_menu(N5110 &lcd); +void menu_continue(N5110 &lcd, Gamepad &pad); + + int main() { int fps = 6; //6 - - pad.init(); - lcd.init(); + init(); + ticker.attach(&timer_isr,1.0f/fps); + lcd.setContrast(0.55); - ticker.attach(&timer_isr,1.0f/fps); - - //int gameover = 0; - main_menu(lcd, pad); - } void timer_isr() @@ -46,11 +48,19 @@ timer_flag = 1; // set flag in ISR } +void init() +{ + pad.init(); + lcd.init(); +} + void main_menu(N5110 &lcd, Gamepad &pad) { + blockhead.init(); + print_main_menu(lcd); int input = user_input(pad); - select_menu_item(lcd, pad, input); + select_main_menu_item(lcd, pad, input); } void print_main_menu(N5110 &lcd) @@ -80,7 +90,7 @@ return input; } -void select_menu_item(N5110 &lcd, Gamepad &pad, int input) +void select_main_menu_item(N5110 &lcd, Gamepad &pad, int input) { switch (input) { case 1: @@ -98,8 +108,8 @@ void menu_playgame(N5110 &lcd, Gamepad &pad) { int gameover = 0; - - blockhead.init(); + + // blockhead.init(); do { @@ -120,8 +130,7 @@ } } while (gameover == 0); - main_menu(lcd, pad); - + menu_continue(lcd, pad); } @@ -129,7 +138,7 @@ { int goback = 0; - + do { if (timer_flag == true) { @@ -157,6 +166,41 @@ } +void select_continue_menu_item(N5110 &lcd, Gamepad &pad, int input) +{ + switch (input) { + case 1: + menu_playgame(lcd, pad); + break; + case 2: + main_menu(lcd, pad); + break; + default: + exit(1); + break; + } +} + +void print_menu_continue(N5110 &lcd) +{ + lcd.clear(); + + lcd.printString("Continue??",0,0); + lcd.printString("A for hell yeh",0,1); + lcd.printString("B for back",0,2); + lcd.refresh(); + +} + +void menu_continue(N5110 &lcd, Gamepad &pad) +{ + blockhead.continueInit(); + + print_menu_continue(lcd); + int input = user_input(pad); + select_continue_menu_item(lcd, pad, input); +} + //rtos /**