![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 26:3319ddd5111d
- Parent:
- 25:230e4163cb6b
- Child:
- 29:b2f63d8c1268
--- a/main.cpp Sun Apr 21 19:50:39 2019 +0000 +++ b/main.cpp Sun Apr 21 21:55:54 2019 +0000 @@ -15,8 +15,12 @@ volatile int timer_flag = 0; void timer_isr(); -int user_input(Gamepad &pad); -void select_menu_item(int input); +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 menu_playgame(N5110 &lcd, Gamepad &pad); +void menu_setcontrast(N5110 &lcd, Gamepad &pad); int main() { @@ -29,26 +33,10 @@ ticker.attach(&timer_isr,1.0f/fps); - int gameover = 0; - - while(1) { - - if (timer_flag == true) { - - timer_flag = 0; // if it has, clear the flag + //int gameover = 0; - lcd.clear(); - - gameover = blockhead.playgame(lcd, pad); - - lcd.refresh(); + main_menu(lcd, pad); - } else { - - sleep(); - - } - } } @@ -58,41 +46,115 @@ timer_flag = 1; // set flag in ISR } -int user_input(Gamepad &pad) +void main_menu(N5110 &lcd, Gamepad &pad) +{ + print_main_menu(lcd); + int input = user_input(pad); + select_menu_item(lcd, pad, input); +} + +void print_main_menu(N5110 &lcd) { - int input; - - - if (pad.check_event(Gamepad::A_PRESSED)) { - input = 1; - } else if (pad.check_event(Gamepad::B_PRESSED)) { - input = 2; - } else { - input = 0; - } - + lcd.clear(); + + lcd.printString("cuntballs",0,0); + lcd.printString("A for game",0,1); + lcd.printString("B for cunt",0,2); + lcd.refresh(); + +} + + +int user_input(Gamepad &pad) +{ + int input = 0; + + do { + if (pad.check_event(Gamepad::A_PRESSED)) { + input = 1; + } else if (pad.check_event(Gamepad::B_PRESSED)) { + input = 2; + } + } while (input == 0); + return input; } -void select_menu_item(int input) { - switch (input) { - case 1: - menu_item_1(); - break; - case 2: - menu_item_2(); - break; - default: - exit(1); - break; - } +void select_menu_item(N5110 &lcd, Gamepad &pad, int input) +{ + switch (input) { + case 1: + menu_playgame(lcd, pad); + break; + case 2: + menu_setcontrast(lcd, pad); + break; + default: + exit(1); + break; + } } -void menu_playgame(N5110 &lcd, Gamepad &pad) +void menu_playgame(N5110 &lcd, Gamepad &pad) +{ + int gameover = 0; + + blockhead.init(); + + do { + + if (timer_flag == true) { + + timer_flag = 0; // if it has, clear the flag + + lcd.clear(); + + gameover = blockhead.playgame(lcd, pad); + + lcd.refresh(); + + } else { + + sleep(); + + } + } while (gameover == 0); + + main_menu(lcd, pad); + + +} + +void menu_setcontrast(N5110 &lcd, Gamepad &pad) { + int goback = 0; + do { + if (timer_flag == true) { + + timer_flag = 0; + + lcd.clear(); + + lcd.printString("cuntballs",0,0); + + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED)) { + goback = 1; + } + + } else { + + sleep(); + + } + } while (goback == 0); + + main_menu(lcd, pad); +} @@ -102,4 +164,4 @@ sprintf(buffer,"%i", gameover); lcd.printString(buffer,0,0); */ - //NEED TO RESET POS CORDS EACH NEW LEVEL TO PREVENT UNNECERSARRY GAME OVER (have fun x) +//NEED TO RESET POS CORDS EACH NEW LEVEL TO PREVENT UNNECERSARRY GAME OVER (have fun x)