James Heavey
/
EL17JH
FINAL VERSION
Diff: main.cpp
- Revision:
- 121:12acab75db8f
- Parent:
- 120:33dabf094a6d
- Child:
- 122:a78a1b98b9b1
--- a/main.cpp Wed May 08 15:04:27 2019 +0000 +++ b/main.cpp Wed May 08 15:41:42 2019 +0000 @@ -65,8 +65,7 @@ title_screen(); // run the title screen } -// initialies all classes and libraries -void init() +void init() // initialies all classes and libraries { // need to initialise LCD and Gamepad lcd.init(); @@ -74,8 +73,7 @@ breakout.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); // init the objects } -// this function draws each frame on the LCD -void render() +void render() // draws each frame on the LCD { // clear screen, re-draw and refresh lcd.clear(); @@ -83,7 +81,7 @@ lcd.refresh(); } -void title_screen() +void title_screen() { tilt = false; // reset the tilt variable so that on start, joystick is default breakout.set_mult_zero(); @@ -120,7 +118,9 @@ void main_menu() -{ +{ + bool menu_toggle = false; // added to delay the while loop condition toggle to prevent button bounce from causing the game to start immediately + lcd.clear(); lcd.printString(" START ",0,1); // start game with default as joystick lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt @@ -132,7 +132,7 @@ int pointer = 1; - while (pad.check_event(Gamepad::A_PRESSED) == false) { + while (menu_toggle == false) { lcd.clear(); lcd.printString(" START ",0,1); // start game with default as joystick lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt @@ -154,6 +154,10 @@ if (pad.check_event(Gamepad::X_PRESSED) & pad.check_event(Gamepad::Y_PRESSED)) { save_hi_score(0); // resets hi score } + wait(0.4); // prevents game from starting immediately upon restart (button bounce bug) + if (pad.check_event(Gamepad::A_PRESSED)) { + menu_toggle = !menu_toggle; + } //printf("Pointer 1 = %d",pointer); } @@ -403,7 +407,7 @@ while (pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED) == false) { lcd.clear(); - lcd.printString(" VICTORY! ",2,0); + lcd.printString(" VICTORY! ",2,0); // flashing score lcd.printString(" CONT = START ",0,4); lcd.printString(" MENU = BACK ",0,5); @@ -552,7 +556,7 @@ breakout.reset_game(); // return game to initial positions } -void flash_hi_score_screen() +void flash_hi_score_screen() // flash the hi score, called when hi score acheieved { lcd.clear(); lcd.printString(" NEW ",0,2);