![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
main.cpp
- Committer:
- adambakerwa
- Date:
- 2019-04-21
- Revision:
- 25:230e4163cb6b
- Parent:
- 24:f5dd1f3db693
- Child:
- 26:3319ddd5111d
File content as of revision 25:230e4163cb6b:
#include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "Runner.h" #include "Levels.h" #include "Animation.h" #include "BlockheadEngine.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; BlockheadEngine blockhead; Ticker ticker; volatile int timer_flag = 0; void timer_isr(); int user_input(Gamepad &pad); void select_menu_item(int input); int main() { int fps = 6; //6 pad.init(); lcd.init(); lcd.setContrast(0.55); 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 lcd.clear(); gameover = blockhead.playgame(lcd, pad); lcd.refresh(); } else { sleep(); } } } void timer_isr() { timer_flag = 1; // set flag in ISR } int user_input(Gamepad &pad) { int input; if (pad.check_event(Gamepad::A_PRESSED)) { input = 1; } else if (pad.check_event(Gamepad::B_PRESSED)) { input = 2; } else { 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 menu_playgame(N5110 &lcd, Gamepad &pad) { //rtos /** char buffer[14]; 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)