James Heavey
/
EL17JH
FINAL VERSION
Diff: main.cpp
- Revision:
- 117:4eedd15f2c3d
- Parent:
- 116:2793d31ca691
- Child:
- 118:a44365bf061a
diff -r 2793d31ca691 -r 4eedd15f2c3d main.cpp --- a/main.cpp Wed May 08 13:38:58 2019 +0000 +++ b/main.cpp Wed May 08 13:57:45 2019 +0000 @@ -1,4 +1,5 @@ ///////// pre-processor directives //////// + #include "mbed.h" #include "Gamepad.h" #include "N5110.h" @@ -6,8 +7,7 @@ #include "Bitmap.h" #include "Sprites.h" #include "SDFileSystem.h" -//#include "Menus.h" -//#include "Game.h" + /////////////// structs ///////////////// struct UserInput { @@ -41,6 +41,8 @@ int get_hi_score(); bool compare_to_hi_score(int score); void print_hi_score(int col,int row); +void reset_victory(int score, int bonus); +void reset_loss(); Bitmap breakwhite(breakwhite_data, 48, 84); // assign the title screen sprites Bitmap breakblack(breakblack_data, 48, 84); @@ -296,10 +298,7 @@ wait(0.4); // delay to help with button bounce } if (pad.check_event(Gamepad::BACK_PRESSED)) { // if BACK pressed, return to the title screen - breakout.reset_paddle_lives(); // resets lives back to 6 - breakout.set_mult_zero(); // reset multiplier - breakout.set_prev_score(0); - breakout.reset_game(); //reset game to initial positions + reset_loss(); title_screen(); } } @@ -394,11 +393,7 @@ wait(0.4); } - breakout.reset_paddle_lives(); // resets lives back to 6 - breakout.set_prev_score(0); // resets prev score to 0 - number_of_frames = 0; - breakout.set_mult_zero(); // reset multiplier - breakout.reset_game(); // return game to initial positions + reset_loss(); title_screen(); } @@ -510,17 +505,10 @@ wait(0.4); if (pad.check_event(Gamepad::START_PRESSED)) { - breakout.set_prev_score(breakout.get_score() + bonus); - number_of_frames = 0; // reset the number of frames - breakout.inc_mult(); // increment multiplier - breakout.reset_game(); // return game to initial positions + reset_victory(breakout.get_score(),bonus); main_game(); } else if (pad.check_event(Gamepad::BACK_PRESSED)) { - breakout.reset_paddle_lives(); // resets lives back to 6 - breakout.set_prev_score(0); // resets prev score to 0 - number_of_frames = 0; // reset the number of frames - breakout.set_mult_zero(); // reset multiplier - breakout.reset_game(); // return game to initial positions + reset_loss(); title_screen(); } } @@ -622,3 +610,20 @@ lcd.printString(buffer,col,row); // prints buffer to the screen } + +void reset_loss() // reset the game when returning to title screen from any point +{ + breakout.reset_paddle_lives(); // resets lives back to 6 + breakout.set_prev_score(0); // resets prev score to 0 + number_of_frames = 0; // reset the number of frames + breakout.set_mult_zero(); // reset multiplier + breakout.reset_game(); // return game to initial positions +} + +void reset_victory(int score, int bonus) // reset the game after a victory +{ + breakout.set_prev_score(score + bonus); // saves score + number_of_frames = 0; // reset the number of frames + breakout.inc_mult(); // increment multiplier + breakout.reset_game(); // return game to initial positions +}