FINAL VERSION

Dependencies:   mbed

Committer:
jamesheavey
Date:
Mon May 06 17:49:36 2019 +0000
Revision:
84:6483503a72fc
Parent:
83:645cdbd79c21
Child:
91:c01a736fb0d9
how to play done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 0:7d4d2023ed9c 1 ///////// pre-processor directives ////////
jamesheavey 0:7d4d2023ed9c 2 #include "mbed.h"
jamesheavey 0:7d4d2023ed9c 3 #include "Gamepad.h"
jamesheavey 0:7d4d2023ed9c 4 #include "N5110.h"
jamesheavey 27:1b5038b0a7a2 5 #include "BreakoutEngine.h"
jamesheavey 3:5719d0fe94ed 6 #include "Bitmap.h"
jamesheavey 8:1ab6d90c4d60 7 #include "Sprites.h"
jamesheavey 0:7d4d2023ed9c 8
jamesheavey 0:7d4d2023ed9c 9 /////////////// structs /////////////////
jamesheavey 79:70510b0102af 10
jamesheavey 0:7d4d2023ed9c 11 struct UserInput {
jamesheavey 0:7d4d2023ed9c 12 Direction d;
jamesheavey 0:7d4d2023ed9c 13 float mag;
jamesheavey 0:7d4d2023ed9c 14 };
jamesheavey 0:7d4d2023ed9c 15 /////////////// objects ///////////////
jamesheavey 79:70510b0102af 16
jamesheavey 0:7d4d2023ed9c 17 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
jamesheavey 0:7d4d2023ed9c 18 Gamepad pad;
jamesheavey 27:1b5038b0a7a2 19 BreakoutEngine breakout;
jamesheavey 0:7d4d2023ed9c 20
jamesheavey 0:7d4d2023ed9c 21 ///////////// prototypes ///////////////
jamesheavey 79:70510b0102af 22
jamesheavey 0:7d4d2023ed9c 23 void init();
jamesheavey 0:7d4d2023ed9c 24 void update_game(UserInput input);
jamesheavey 0:7d4d2023ed9c 25 void render();
jamesheavey 53:8e3da0b58fe9 26 void main_menu();
jamesheavey 51:9d5c10a88b22 27 void settings();
jamesheavey 50:3da51f34e253 28 void how_to_play();
jamesheavey 79:70510b0102af 29 void loss_screen();
jamesheavey 58:a159cd976aca 30 void victory_screen();
jamesheavey 49:31eb7807dbd3 31 void title_screen();
jamesheavey 72:7254d2a8a1cd 32 void main_game(bool tilt,float sens);
jamesheavey 58:a159cd976aca 33 void flash_screen(N5110 &lcd);
jamesheavey 59:fdc05d5778a6 34 void countdown();
jamesheavey 47:1d1a827be81b 35
jamesheavey 47:1d1a827be81b 36 bool tilt = false;
jamesheavey 72:7254d2a8a1cd 37 float sens = 0.5; // default sens
jamesheavey 0:7d4d2023ed9c 38
jamesheavey 0:7d4d2023ed9c 39 ///////////// functions ////////////////
jamesheavey 79:70510b0102af 40
jamesheavey 0:7d4d2023ed9c 41 int main()
jamesheavey 79:70510b0102af 42 {
jamesheavey 58:a159cd976aca 43 init(); // initialise the gamepad
jamesheavey 58:a159cd976aca 44 title_screen(); // run the title screen
jamesheavey 3:5719d0fe94ed 45
jamesheavey 0:7d4d2023ed9c 46 }
jamesheavey 0:7d4d2023ed9c 47
jamesheavey 0:7d4d2023ed9c 48 // initialies all classes and libraries
jamesheavey 56:f9e586348e0b 49 void init()
jamesheavey 0:7d4d2023ed9c 50 {
jamesheavey 0:7d4d2023ed9c 51 // need to initialise LCD and Gamepad
jamesheavey 0:7d4d2023ed9c 52 lcd.init();
jamesheavey 0:7d4d2023ed9c 53 pad.init();
jamesheavey 72:7254d2a8a1cd 54 breakout.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); // init the objects
jamesheavey 0:7d4d2023ed9c 55
jamesheavey 0:7d4d2023ed9c 56 }
jamesheavey 0:7d4d2023ed9c 57
jamesheavey 0:7d4d2023ed9c 58 // this function draws each frame on the LCD
jamesheavey 0:7d4d2023ed9c 59 void render()
jamesheavey 0:7d4d2023ed9c 60 {
jamesheavey 0:7d4d2023ed9c 61 // clear screen, re-draw and refresh
jamesheavey 0:7d4d2023ed9c 62 lcd.clear();
jamesheavey 26:25eea19c5fbe 63 breakout.draw(lcd);
jamesheavey 0:7d4d2023ed9c 64 lcd.refresh();
jamesheavey 0:7d4d2023ed9c 65 }
jamesheavey 0:7d4d2023ed9c 66
jamesheavey 58:a159cd976aca 67 void title_screen() {
jamesheavey 58:a159cd976aca 68 tilt = false; // reset the tilt variable so that on start, joystick is default
jamesheavey 58:a159cd976aca 69
jamesheavey 58:a159cd976aca 70 Bitmap breakwhite(breakwhite_data, 48, 84); // assign the title screen sprites
jamesheavey 58:a159cd976aca 71 Bitmap breakblack(breakblack_data, 48, 84);
jamesheavey 58:a159cd976aca 72
jamesheavey 58:a159cd976aca 73 lcd.clear();
jamesheavey 58:a159cd976aca 74
jamesheavey 58:a159cd976aca 75 breakblack.render(lcd, 0, 0); // render the first frame
jamesheavey 58:a159cd976aca 76 lcd.refresh();
jamesheavey 58:a159cd976aca 77 pad.leds_off();
jamesheavey 58:a159cd976aca 78 wait(0.5);
jamesheavey 58:a159cd976aca 79
jamesheavey 58:a159cd976aca 80 while (pad.check_event(Gamepad::START_PRESSED) == false) { // while start is not pressed alternate sprites
jamesheavey 58:a159cd976aca 81
jamesheavey 58:a159cd976aca 82 lcd.clear();
jamesheavey 58:a159cd976aca 83
jamesheavey 58:a159cd976aca 84 breakwhite.render(lcd, 0, 0);
jamesheavey 58:a159cd976aca 85 lcd.refresh();
jamesheavey 58:a159cd976aca 86 pad.leds_on();
jamesheavey 58:a159cd976aca 87 wait(0.5);
jamesheavey 58:a159cd976aca 88
jamesheavey 58:a159cd976aca 89 lcd.clear();
jamesheavey 58:a159cd976aca 90
jamesheavey 58:a159cd976aca 91 breakblack.render(lcd, 0, 0);
jamesheavey 58:a159cd976aca 92 lcd.refresh();
jamesheavey 58:a159cd976aca 93 pad.leds_off();
jamesheavey 58:a159cd976aca 94 wait(0.5);
jamesheavey 58:a159cd976aca 95 }
jamesheavey 58:a159cd976aca 96
jamesheavey 58:a159cd976aca 97 pad.tone(750.0,0.3);
jamesheavey 58:a159cd976aca 98 wait(0.2);
jamesheavey 58:a159cd976aca 99 main_menu(); // load main menu
jamesheavey 58:a159cd976aca 100 }
jamesheavey 58:a159cd976aca 101
jamesheavey 58:a159cd976aca 102
jamesheavey 53:8e3da0b58fe9 103 void main_menu() {
jamesheavey 14:38560375d420 104
jamesheavey 50:3da51f34e253 105 lcd.clear();
jamesheavey 73:54ab819609bc 106 lcd.printString(" START ",0,1); // start with default as joystick
jamesheavey 73:54ab819609bc 107 lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt
jamesheavey 73:54ab819609bc 108 lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff
jamesheavey 50:3da51f34e253 109 lcd.refresh();
jamesheavey 56:f9e586348e0b 110 wait(0.3);
jamesheavey 50:3da51f34e253 111
jamesheavey 73:54ab819609bc 112 int pointer = 1;
jamesheavey 52:652b5f51319d 113
jamesheavey 58:a159cd976aca 114 while (pad.check_event(Gamepad::A_PRESSED) == false) {
jamesheavey 53:8e3da0b58fe9 115 lcd.clear();
jamesheavey 73:54ab819609bc 116 lcd.printString(" START ",0,1); // start with default as joystick
jamesheavey 73:54ab819609bc 117 lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt
jamesheavey 73:54ab819609bc 118 lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff
jamesheavey 56:f9e586348e0b 119 lcd.printString(" >",0,pointer);
jamesheavey 53:8e3da0b58fe9 120 lcd.refresh();
jamesheavey 53:8e3da0b58fe9 121 wait(0.1);
jamesheavey 73:54ab819609bc 122 if (pad.check_event(Gamepad::L_PRESSED) && pointer > 1) { // if L is pressed and pointer isnt already on START, move it up one line
jamesheavey 50:3da51f34e253 123 pointer -= 1;
jamesheavey 53:8e3da0b58fe9 124 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 125 wait(0.1);
jamesheavey 73:54ab819609bc 126 } else if (pad.check_event(Gamepad::R_PRESSED) && pointer < 3) { // if R is pressed and pointer isnt already on HOW TO PLAY, move it down one line
jamesheavey 50:3da51f34e253 127 pointer += 1;
jamesheavey 53:8e3da0b58fe9 128 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 129 wait(0.1);
jamesheavey 50:3da51f34e253 130 }
jamesheavey 3:5719d0fe94ed 131
jamesheavey 50:3da51f34e253 132 }
jamesheavey 73:54ab819609bc 133 if (pointer == 1) { // if START was selected on exit of the while loop, run main game with the appropriate tilt/joystick setting
jamesheavey 56:f9e586348e0b 134 pad.tone(750.0,0.3);
jamesheavey 72:7254d2a8a1cd 135 main_game(tilt,sens);
jamesheavey 51:9d5c10a88b22 136 }
jamesheavey 73:54ab819609bc 137 else if (pointer == 2){ // if SETTINGS was selected, enter the settings menu
jamesheavey 56:f9e586348e0b 138 pad.tone(750.0,0.3);
jamesheavey 51:9d5c10a88b22 139 settings();
jamesheavey 51:9d5c10a88b22 140 }
jamesheavey 73:54ab819609bc 141 else if (pointer == 3){ // if HOW TO PLAY WAS SELECTED, display instructions on how to play
jamesheavey 56:f9e586348e0b 142 pad.tone(750.0,0.3);
jamesheavey 51:9d5c10a88b22 143 how_to_play();
jamesheavey 51:9d5c10a88b22 144 }
jamesheavey 50:3da51f34e253 145 }
jamesheavey 50:3da51f34e253 146
jamesheavey 52:652b5f51319d 147 void settings() {
jamesheavey 50:3da51f34e253 148
jamesheavey 50:3da51f34e253 149 lcd.clear();
jamesheavey 72:7254d2a8a1cd 150 lcd.printString(" JOYSTICK ",0,1); // choose joystick
jamesheavey 72:7254d2a8a1cd 151 lcd.printString(" TILT ",0,2); // choose tilt
jamesheavey 72:7254d2a8a1cd 152 lcd.printString("SENS :",0,4);
jamesheavey 72:7254d2a8a1cd 153 lcd.drawRect(42,30, 40,10,FILL_TRANSPARENT);
jamesheavey 72:7254d2a8a1cd 154 lcd.drawRect(42,30,40 * pad.read_pot() + 1,10,FILL_BLACK); // have it so it fills half the transparent one (default position)
jamesheavey 72:7254d2a8a1cd 155 // the sens can only change via pot when the pointer is on the right pointer
jamesheavey 50:3da51f34e253 156 lcd.refresh();
jamesheavey 75:d96b177585aa 157 wait(0.4);
jamesheavey 53:8e3da0b58fe9 158
jamesheavey 72:7254d2a8a1cd 159 int pointer = 1;
jamesheavey 52:652b5f51319d 160
jamesheavey 58:a159cd976aca 161 while (pad.check_event(Gamepad::B_PRESSED) == false) { // while B is not pressed to return to main menu
jamesheavey 53:8e3da0b58fe9 162 lcd.clear();
jamesheavey 72:7254d2a8a1cd 163 lcd.printString(" JOYSTICK ",0,1); // choose joystick
jamesheavey 72:7254d2a8a1cd 164 lcd.printString(" TILT ",0,2); // choose tilt
jamesheavey 72:7254d2a8a1cd 165 lcd.printString("SENS :",0,4);
jamesheavey 56:f9e586348e0b 166 lcd.printString(" >",0,pointer);
jamesheavey 72:7254d2a8a1cd 167 lcd.drawRect(42,30, 40,10,FILL_TRANSPARENT);
jamesheavey 72:7254d2a8a1cd 168 lcd.drawRect(42,30,40 * pad.read_pot() + 1,10,FILL_BLACK); // have it so it fills half the transparent one (default position)
jamesheavey 53:8e3da0b58fe9 169 lcd.refresh();
jamesheavey 53:8e3da0b58fe9 170 wait(0.1);
jamesheavey 72:7254d2a8a1cd 171 if (pad.check_event(Gamepad::L_PRESSED) && pointer > 1) { // if L is pressed and pointer isnt already on JOYSTICK, move it up one line
jamesheavey 50:3da51f34e253 172 pointer -= 1;
jamesheavey 53:8e3da0b58fe9 173 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 174 wait(0.1);
jamesheavey 72:7254d2a8a1cd 175 } else if (pad.check_event(Gamepad::R_PRESSED) && pointer < 2) { // if R is pressed and pointer isnt already on TILT, move it down one line
jamesheavey 50:3da51f34e253 176 pointer += 1;
jamesheavey 53:8e3da0b58fe9 177 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 178 wait(0.1);
jamesheavey 50:3da51f34e253 179 }
jamesheavey 16:1761dfe801af 180
jamesheavey 58:a159cd976aca 181 if (pad.check_event(Gamepad::A_PRESSED)) { // if A is pressed, switch the tilt option accordingly
jamesheavey 56:f9e586348e0b 182 pad.tone(750.0,0.3);
jamesheavey 56:f9e586348e0b 183 wait(0.1);
jamesheavey 74:dfb1d693d8e3 184 if (pointer == 1) { // if A is pressed on JOYSTICK, tilt = false
jamesheavey 57:d498dd835cfc 185 tilt = false;
jamesheavey 57:d498dd835cfc 186 }
jamesheavey 74:dfb1d693d8e3 187 else if (pointer == 2) { // if A is pressed on TILT, tilt == true
jamesheavey 57:d498dd835cfc 188 tilt = true;
jamesheavey 57:d498dd835cfc 189 }
jamesheavey 58:a159cd976aca 190 }
jamesheavey 55:b7bde601c23e 191
jamesheavey 58:a159cd976aca 192 if (pad.check_event(Gamepad::B_PRESSED)) { // when B is pressed return to main menu
jamesheavey 56:f9e586348e0b 193 pad.tone(750.0,0.3);
jamesheavey 72:7254d2a8a1cd 194 sens = pad.read_pot() + 0.5f;
jamesheavey 78:b523226b7572 195 wait(0.3);
jamesheavey 50:3da51f34e253 196 main_menu();
jamesheavey 16:1761dfe801af 197 }
jamesheavey 0:7d4d2023ed9c 198 }
jamesheavey 10:9f445faa892c 199 }
jamesheavey 10:9f445faa892c 200
jamesheavey 52:652b5f51319d 201 void how_to_play() {
jamesheavey 84:6483503a72fc 202 Bitmap arrowup(arrowup_data, 5, 7); // assign the arrow up sprite data
jamesheavey 84:6483503a72fc 203 Bitmap arrowdown(arrowdown_data, 5, 7); // assign the arrow down sprite data
jamesheavey 84:6483503a72fc 204
jamesheavey 84:6483503a72fc 205 lcd.clear();
jamesheavey 84:6483503a72fc 206 lcd.printString(" B = LASER ",0,0);
jamesheavey 84:6483503a72fc 207 lcd.printString(" START = PAUSE ",0,1);
jamesheavey 84:6483503a72fc 208 lcd.printString(" DESTROY ALL ",0,2);
jamesheavey 84:6483503a72fc 209 lcd.printString(" BRICKS ",0,3);
jamesheavey 84:6483503a72fc 210 arrowdown.render(lcd, 38, 43);
jamesheavey 84:6483503a72fc 211 lcd.refresh();
jamesheavey 84:6483503a72fc 212 wait(0.4);
jamesheavey 58:a159cd976aca 213 while (pad.check_event(Gamepad::B_PRESSED) == false) { // while B is not pressed to return to main menu display instruction on how to interact with the game
jamesheavey 84:6483503a72fc 214
jamesheavey 84:6483503a72fc 215 if (pad.check_event(Gamepad::R_PRESSED)){
jamesheavey 84:6483503a72fc 216 lcd.clear();
jamesheavey 84:6483503a72fc 217 lcd.printString(" CONTINUE TO ",0,2);
jamesheavey 84:6483503a72fc 218 lcd.printString("INCREASE SCORE. ",0,3);
jamesheavey 84:6483503a72fc 219 arrowup.render(lcd, 38, 0);
jamesheavey 84:6483503a72fc 220 lcd.refresh();
jamesheavey 84:6483503a72fc 221 wait(0.1);
jamesheavey 84:6483503a72fc 222 }
jamesheavey 84:6483503a72fc 223 if (pad.check_event(Gamepad::L_PRESSED)){
jamesheavey 84:6483503a72fc 224 lcd.clear();
jamesheavey 84:6483503a72fc 225 lcd.printString(" B = LASER ",0,0);
jamesheavey 84:6483503a72fc 226 lcd.printString(" START = PAUSE ",0,1);
jamesheavey 84:6483503a72fc 227 lcd.printString(" DESTROY ALL ",0,2);
jamesheavey 84:6483503a72fc 228 lcd.printString(" BRICKS ",0,3);
jamesheavey 84:6483503a72fc 229 arrowdown.render(lcd, 38, 43);
jamesheavey 84:6483503a72fc 230 lcd.refresh();
jamesheavey 84:6483503a72fc 231 wait(0.1);
jamesheavey 84:6483503a72fc 232 }
jamesheavey 50:3da51f34e253 233 }
jamesheavey 84:6483503a72fc 234 wait(0.3);
jamesheavey 58:a159cd976aca 235 main_menu(); // when B is pressed, the loop is exited and main menu is entered once again
jamesheavey 58:a159cd976aca 236 }
jamesheavey 58:a159cd976aca 237
jamesheavey 58:a159cd976aca 238
jamesheavey 72:7254d2a8a1cd 239 void main_game(bool tilt, float sens) {
jamesheavey 58:a159cd976aca 240 int fps = 8; // frames per second
jamesheavey 58:a159cd976aca 241 bool pause = false; // set pause screen to false
jamesheavey 58:a159cd976aca 242
jamesheavey 58:a159cd976aca 243 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 244
jamesheavey 59:fdc05d5778a6 245 countdown(); // run the countdown
jamesheavey 58:a159cd976aca 246
jamesheavey 58:a159cd976aca 247 render(); // first draw the initial frame
jamesheavey 58:a159cd976aca 248 wait(1.0f/fps); // and wait for one frame period
jamesheavey 58:a159cd976aca 249
jamesheavey 58:a159cd976aca 250
jamesheavey 58:a159cd976aca 251 // game loop - read input, update the game state and render the display
jamesheavey 58:a159cd976aca 252 while (1) {
jamesheavey 72:7254d2a8a1cd 253 breakout.read_input(pad,tilt,sens); // read input from pad
jamesheavey 59:fdc05d5778a6 254 breakout.update(pad); // update game
jamesheavey 59:fdc05d5778a6 255 render(); // draw new frame
jamesheavey 75:d96b177585aa 256
jamesheavey 81:735e5ee2c92a 257 if (breakout.check_loss(pad) == true) { // if life lost flash screen
jamesheavey 58:a159cd976aca 258 flash_screen(lcd);
jamesheavey 58:a159cd976aca 259 }
jamesheavey 83:645cdbd79c21 260 if (pad.check_event(Gamepad::START_PRESSED) == true) { // if BACK pressed, toggle pause
jamesheavey 58:a159cd976aca 261 pause = !pause;
jamesheavey 58:a159cd976aca 262 }
jamesheavey 75:d96b177585aa 263
jamesheavey 59:fdc05d5778a6 264 while (pause == true) { // if pause is true, display pause screen
jamesheavey 58:a159cd976aca 265 lcd.clear();
jamesheavey 83:645cdbd79c21 266 lcd.printString(" PAUSED ",0,1);
jamesheavey 83:645cdbd79c21 267 lcd.printString(" START = PLAY",0,3);
jamesheavey 83:645cdbd79c21 268 lcd.printString(" BACK = MENU",0,4);
jamesheavey 58:a159cd976aca 269 lcd.refresh();
jamesheavey 83:645cdbd79c21 270 if (pad.check_event(Gamepad::START_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen
jamesheavey 58:a159cd976aca 271 pause = !pause;
jamesheavey 58:a159cd976aca 272 }
jamesheavey 83:645cdbd79c21 273 if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen
jamesheavey 83:645cdbd79c21 274 title_screen();
jamesheavey 83:645cdbd79c21 275 }
jamesheavey 58:a159cd976aca 276 }
jamesheavey 75:d96b177585aa 277
jamesheavey 79:70510b0102af 278 if (breakout.get_lives() == 0) { // when all lives lost, enter loss screen
jamesheavey 59:fdc05d5778a6 279 pad.leds_off(); //turns last led off (doesnt run through and update board so last led doent turn off via lives leds
jamesheavey 81:735e5ee2c92a 280 breakout.reset_game();
jamesheavey 62:64559062e0ec 281 breakout.set_mult_zero();
jamesheavey 79:70510b0102af 282 loss_screen();
jamesheavey 58:a159cd976aca 283 }
jamesheavey 75:d96b177585aa 284
jamesheavey 59:fdc05d5778a6 285 if (breakout.get_num_left() == 0) { // when all bricks destroyed, display victory screen
jamesheavey 81:735e5ee2c92a 286 breakout.reset_game();
jamesheavey 62:64559062e0ec 287 breakout.inc_mult();
jamesheavey 58:a159cd976aca 288 victory_screen();
jamesheavey 58:a159cd976aca 289 }
jamesheavey 58:a159cd976aca 290 wait(1.0f/fps);
jamesheavey 58:a159cd976aca 291 }
jamesheavey 50:3da51f34e253 292 }
jamesheavey 16:1761dfe801af 293
jamesheavey 79:70510b0102af 294 void loss_screen()
jamesheavey 64:c3426b417ad9 295 {
jamesheavey 15:b867a6620f96 296 lcd.clear();
jamesheavey 64:c3426b417ad9 297 char buffer1[14];
jamesheavey 64:c3426b417ad9 298 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 299 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 300 lcd.printString(" RESTART? ",2,1);
jamesheavey 72:7254d2a8a1cd 301 lcd.printString(" PRESS START ",1,4);
jamesheavey 15:b867a6620f96 302 lcd.refresh();
jamesheavey 15:b867a6620f96 303 pad.tone(750.0,0.3);
jamesheavey 15:b867a6620f96 304 wait(0.4);
jamesheavey 15:b867a6620f96 305
jamesheavey 15:b867a6620f96 306 pad.tone(300.0,0.3);
jamesheavey 15:b867a6620f96 307 wait(0.4);
jamesheavey 10:9f445faa892c 308
jamesheavey 10:9f445faa892c 309 while (pad.check_event(Gamepad::START_PRESSED) == false) {
jamesheavey 10:9f445faa892c 310 lcd.clear();
jamesheavey 64:c3426b417ad9 311
jamesheavey 64:c3426b417ad9 312 lcd.printString(" RESTART? ",2,1); //print score here
jamesheavey 64:c3426b417ad9 313 lcd.printString(" PRESS START ",1,4);
jamesheavey 10:9f445faa892c 314 lcd.refresh();
jamesheavey 64:c3426b417ad9 315
jamesheavey 64:c3426b417ad9 316 wait(0.4);
jamesheavey 64:c3426b417ad9 317
jamesheavey 64:c3426b417ad9 318 lcd.clear();
jamesheavey 64:c3426b417ad9 319
jamesheavey 64:c3426b417ad9 320 char buffer1[14];
jamesheavey 64:c3426b417ad9 321 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 322 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 323 lcd.printString(" RESTART? ",2,1); //print score here
jamesheavey 64:c3426b417ad9 324 lcd.printString(" PRESS START ",1,4);
jamesheavey 64:c3426b417ad9 325 lcd.refresh();
jamesheavey 64:c3426b417ad9 326
jamesheavey 64:c3426b417ad9 327 wait(0.4);
jamesheavey 10:9f445faa892c 328 }
jamesheavey 64:c3426b417ad9 329 breakout.set_prev_score(0);
jamesheavey 49:31eb7807dbd3 330 title_screen();
jamesheavey 10:9f445faa892c 331 }
jamesheavey 10:9f445faa892c 332
jamesheavey 64:c3426b417ad9 333 void victory_screen()
jamesheavey 64:c3426b417ad9 334 {
jamesheavey 15:b867a6620f96 335 lcd.clear();
jamesheavey 64:c3426b417ad9 336 char buffer1[14];
jamesheavey 64:c3426b417ad9 337 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 338 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 43:81d22f68dfae 339 lcd.printString(" VICTORY! ",2,1);
jamesheavey 47:1d1a827be81b 340 lcd.printString(" CONT = START ",0,4); // print score here
jamesheavey 47:1d1a827be81b 341 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 15:b867a6620f96 342 lcd.refresh();
jamesheavey 22:fa2e0b58043a 343 pad.tone(2500.0,0.1);
jamesheavey 22:fa2e0b58043a 344 wait(0.4);
jamesheavey 15:b867a6620f96 345
jamesheavey 22:fa2e0b58043a 346 pad.tone(2500.0,0.1);
jamesheavey 22:fa2e0b58043a 347 wait(0.2);
jamesheavey 15:b867a6620f96 348
jamesheavey 15:b867a6620f96 349 pad.tone(4000.0,0.6);
jamesheavey 15:b867a6620f96 350 wait(0.6);
jamesheavey 43:81d22f68dfae 351 while (pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED) == false) {
jamesheavey 13:418a71b24b37 352 lcd.clear();
jamesheavey 43:81d22f68dfae 353
jamesheavey 43:81d22f68dfae 354 lcd.printString(" VICTORY! ",2,1);
jamesheavey 47:1d1a827be81b 355 lcd.printString(" CONT = START ",0,4);
jamesheavey 47:1d1a827be81b 356 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 43:81d22f68dfae 357
jamesheavey 13:418a71b24b37 358 lcd.refresh();
jamesheavey 15:b867a6620f96 359
jamesheavey 64:c3426b417ad9 360 wait(0.4);
jamesheavey 64:c3426b417ad9 361
jamesheavey 64:c3426b417ad9 362 lcd.clear();
jamesheavey 64:c3426b417ad9 363
jamesheavey 64:c3426b417ad9 364 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 365 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 366 lcd.printString(" VICTORY! ",2,1);
jamesheavey 64:c3426b417ad9 367 lcd.printString(" CONT = START ",0,4); // print score here
jamesheavey 64:c3426b417ad9 368 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 64:c3426b417ad9 369 lcd.refresh();
jamesheavey 75:d96b177585aa 370
jamesheavey 64:c3426b417ad9 371 pad.tone(2500.0,0.1);
jamesheavey 64:c3426b417ad9 372
jamesheavey 64:c3426b417ad9 373 lcd.refresh();
jamesheavey 64:c3426b417ad9 374
jamesheavey 64:c3426b417ad9 375 wait(0.4);
jamesheavey 64:c3426b417ad9 376
jamesheavey 43:81d22f68dfae 377 if (pad.check_event(Gamepad::START_PRESSED)) {
jamesheavey 64:c3426b417ad9 378 breakout.set_prev_score(breakout.get_score());
jamesheavey 72:7254d2a8a1cd 379 main_game(tilt,sens);
jamesheavey 43:81d22f68dfae 380 }
jamesheavey 43:81d22f68dfae 381 else if (pad.check_event(Gamepad::BACK_PRESSED)) {
jamesheavey 64:c3426b417ad9 382 breakout.set_prev_score(0);
jamesheavey 49:31eb7807dbd3 383 title_screen();
jamesheavey 43:81d22f68dfae 384 }
jamesheavey 13:418a71b24b37 385 }
jamesheavey 13:418a71b24b37 386 }
jamesheavey 13:418a71b24b37 387
jamesheavey 59:fdc05d5778a6 388 void flash_screen(N5110 &lcd) { // move to engine
jamesheavey 58:a159cd976aca 389 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 390 wait(0.1);
jamesheavey 58:a159cd976aca 391 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 392 wait(0.1);
jamesheavey 58:a159cd976aca 393 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 394 wait(0.1);
jamesheavey 47:1d1a827be81b 395 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 396 wait(0.1);
jamesheavey 58:a159cd976aca 397 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 398 wait(0.1);
jamesheavey 58:a159cd976aca 399 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 400 wait(0.1);
jamesheavey 58:a159cd976aca 401 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 402 wait(0.1);
jamesheavey 58:a159cd976aca 403 lcd.setBrightness(1);
jamesheavey 59:fdc05d5778a6 404 }
jamesheavey 59:fdc05d5778a6 405
jamesheavey 59:fdc05d5778a6 406 void countdown() {
jamesheavey 59:fdc05d5778a6 407 Bitmap three(three_data, 48, 84); // assign the 3 sprite data
jamesheavey 59:fdc05d5778a6 408 Bitmap two(two_data, 48, 84); // assign the 2 sprite data
jamesheavey 59:fdc05d5778a6 409 Bitmap one(one_data, 48, 84); // assign the 1 sprite data
jamesheavey 59:fdc05d5778a6 410
jamesheavey 59:fdc05d5778a6 411 lcd.clear();
jamesheavey 59:fdc05d5778a6 412 three.render(lcd, 0, 0); // render the 3
jamesheavey 59:fdc05d5778a6 413 lcd.refresh();
jamesheavey 59:fdc05d5778a6 414 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 415 wait(1); // wait 1 second
jamesheavey 59:fdc05d5778a6 416
jamesheavey 59:fdc05d5778a6 417 lcd.clear();
jamesheavey 59:fdc05d5778a6 418 two.render(lcd, 0, 0); // render 2
jamesheavey 59:fdc05d5778a6 419 lcd.refresh();
jamesheavey 59:fdc05d5778a6 420 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 421 wait(1); // wait 1 second
jamesheavey 59:fdc05d5778a6 422
jamesheavey 59:fdc05d5778a6 423 lcd.clear();
jamesheavey 59:fdc05d5778a6 424 one.render(lcd, 0, 0); // render 1
jamesheavey 59:fdc05d5778a6 425 lcd.refresh();
jamesheavey 59:fdc05d5778a6 426 pad.tone(1000.0,1);
jamesheavey 59:fdc05d5778a6 427 wait(1); // wait 1 second
jamesheavey 58:a159cd976aca 428 }