FINAL VERSION

Dependencies:   mbed

Committer:
jamesheavey
Date:
Mon May 06 14:29:15 2019 +0000
Revision:
82:d1341d632890
Parent:
81:735e5ee2c92a
Child:
83:645cdbd79c21
bit cleaner

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 58:a159cd976aca 202 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 50:3da51f34e253 203 lcd.clear();
jamesheavey 50:3da51f34e253 204 lcd.printString(" explain ",2,2);
jamesheavey 50:3da51f34e253 205 lcd.printString(" PRESS B ",1,4);
jamesheavey 50:3da51f34e253 206 lcd.refresh();
jamesheavey 53:8e3da0b58fe9 207 wait(0.1);
jamesheavey 50:3da51f34e253 208 }
jamesheavey 58:a159cd976aca 209 main_menu(); // when B is pressed, the loop is exited and main menu is entered once again
jamesheavey 58:a159cd976aca 210 }
jamesheavey 58:a159cd976aca 211
jamesheavey 58:a159cd976aca 212
jamesheavey 72:7254d2a8a1cd 213 void main_game(bool tilt, float sens) {
jamesheavey 58:a159cd976aca 214 int fps = 8; // frames per second
jamesheavey 58:a159cd976aca 215 bool pause = false; // set pause screen to false
jamesheavey 58:a159cd976aca 216
jamesheavey 58:a159cd976aca 217 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 218
jamesheavey 59:fdc05d5778a6 219 countdown(); // run the countdown
jamesheavey 58:a159cd976aca 220
jamesheavey 58:a159cd976aca 221 render(); // first draw the initial frame
jamesheavey 58:a159cd976aca 222 wait(1.0f/fps); // and wait for one frame period
jamesheavey 58:a159cd976aca 223
jamesheavey 58:a159cd976aca 224
jamesheavey 58:a159cd976aca 225 // game loop - read input, update the game state and render the display
jamesheavey 58:a159cd976aca 226 while (1) {
jamesheavey 72:7254d2a8a1cd 227 breakout.read_input(pad,tilt,sens); // read input from pad
jamesheavey 59:fdc05d5778a6 228 breakout.update(pad); // update game
jamesheavey 59:fdc05d5778a6 229 render(); // draw new frame
jamesheavey 75:d96b177585aa 230
jamesheavey 81:735e5ee2c92a 231 if (breakout.check_loss(pad) == true) { // if life lost flash screen
jamesheavey 58:a159cd976aca 232 flash_screen(lcd);
jamesheavey 58:a159cd976aca 233 }
jamesheavey 59:fdc05d5778a6 234 if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause
jamesheavey 58:a159cd976aca 235 pause = !pause;
jamesheavey 58:a159cd976aca 236 }
jamesheavey 75:d96b177585aa 237
jamesheavey 59:fdc05d5778a6 238 while (pause == true) { // if pause is true, display pause screen
jamesheavey 58:a159cd976aca 239 lcd.clear();
jamesheavey 58:a159cd976aca 240 lcd.printString(" PAUSED ",0,2);
jamesheavey 58:a159cd976aca 241 lcd.refresh();
jamesheavey 59:fdc05d5778a6 242 if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen
jamesheavey 58:a159cd976aca 243 pause = !pause;
jamesheavey 58:a159cd976aca 244 }
jamesheavey 75:d96b177585aa 245 wait(0.4);
jamesheavey 58:a159cd976aca 246 }
jamesheavey 75:d96b177585aa 247
jamesheavey 79:70510b0102af 248 if (breakout.get_lives() == 0) { // when all lives lost, enter loss screen
jamesheavey 59:fdc05d5778a6 249 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 250 breakout.reset_game();
jamesheavey 62:64559062e0ec 251 breakout.set_mult_zero();
jamesheavey 79:70510b0102af 252 loss_screen();
jamesheavey 58:a159cd976aca 253 }
jamesheavey 75:d96b177585aa 254
jamesheavey 59:fdc05d5778a6 255 if (breakout.get_num_left() == 0) { // when all bricks destroyed, display victory screen
jamesheavey 81:735e5ee2c92a 256 breakout.reset_game();
jamesheavey 62:64559062e0ec 257 breakout.inc_mult();
jamesheavey 58:a159cd976aca 258 victory_screen();
jamesheavey 58:a159cd976aca 259 }
jamesheavey 58:a159cd976aca 260 wait(1.0f/fps);
jamesheavey 58:a159cd976aca 261 }
jamesheavey 50:3da51f34e253 262 }
jamesheavey 16:1761dfe801af 263
jamesheavey 79:70510b0102af 264 void loss_screen()
jamesheavey 64:c3426b417ad9 265 {
jamesheavey 15:b867a6620f96 266 lcd.clear();
jamesheavey 64:c3426b417ad9 267 char buffer1[14];
jamesheavey 64:c3426b417ad9 268 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 269 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 270 lcd.printString(" RESTART? ",2,1);
jamesheavey 72:7254d2a8a1cd 271 lcd.printString(" PRESS START ",1,4);
jamesheavey 15:b867a6620f96 272 lcd.refresh();
jamesheavey 15:b867a6620f96 273 pad.tone(750.0,0.3);
jamesheavey 15:b867a6620f96 274 wait(0.4);
jamesheavey 15:b867a6620f96 275
jamesheavey 15:b867a6620f96 276 pad.tone(300.0,0.3);
jamesheavey 15:b867a6620f96 277 wait(0.4);
jamesheavey 10:9f445faa892c 278
jamesheavey 10:9f445faa892c 279 while (pad.check_event(Gamepad::START_PRESSED) == false) {
jamesheavey 10:9f445faa892c 280 lcd.clear();
jamesheavey 64:c3426b417ad9 281
jamesheavey 64:c3426b417ad9 282 lcd.printString(" RESTART? ",2,1); //print score here
jamesheavey 64:c3426b417ad9 283 lcd.printString(" PRESS START ",1,4);
jamesheavey 10:9f445faa892c 284 lcd.refresh();
jamesheavey 64:c3426b417ad9 285
jamesheavey 64:c3426b417ad9 286 wait(0.4);
jamesheavey 64:c3426b417ad9 287
jamesheavey 64:c3426b417ad9 288 lcd.clear();
jamesheavey 64:c3426b417ad9 289
jamesheavey 64:c3426b417ad9 290 char buffer1[14];
jamesheavey 64:c3426b417ad9 291 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 292 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 293 lcd.printString(" RESTART? ",2,1); //print score here
jamesheavey 64:c3426b417ad9 294 lcd.printString(" PRESS START ",1,4);
jamesheavey 64:c3426b417ad9 295 lcd.refresh();
jamesheavey 64:c3426b417ad9 296
jamesheavey 64:c3426b417ad9 297 wait(0.4);
jamesheavey 10:9f445faa892c 298 }
jamesheavey 64:c3426b417ad9 299 breakout.set_prev_score(0);
jamesheavey 49:31eb7807dbd3 300 title_screen();
jamesheavey 10:9f445faa892c 301 }
jamesheavey 10:9f445faa892c 302
jamesheavey 64:c3426b417ad9 303 void victory_screen()
jamesheavey 64:c3426b417ad9 304 {
jamesheavey 15:b867a6620f96 305 lcd.clear();
jamesheavey 64:c3426b417ad9 306 char buffer1[14];
jamesheavey 64:c3426b417ad9 307 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 308 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 43:81d22f68dfae 309 lcd.printString(" VICTORY! ",2,1);
jamesheavey 47:1d1a827be81b 310 lcd.printString(" CONT = START ",0,4); // print score here
jamesheavey 47:1d1a827be81b 311 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 15:b867a6620f96 312 lcd.refresh();
jamesheavey 22:fa2e0b58043a 313 pad.tone(2500.0,0.1);
jamesheavey 22:fa2e0b58043a 314 wait(0.4);
jamesheavey 15:b867a6620f96 315
jamesheavey 22:fa2e0b58043a 316 pad.tone(2500.0,0.1);
jamesheavey 22:fa2e0b58043a 317 wait(0.2);
jamesheavey 15:b867a6620f96 318
jamesheavey 15:b867a6620f96 319 pad.tone(4000.0,0.6);
jamesheavey 15:b867a6620f96 320 wait(0.6);
jamesheavey 43:81d22f68dfae 321 while (pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED) == false) {
jamesheavey 13:418a71b24b37 322 lcd.clear();
jamesheavey 43:81d22f68dfae 323
jamesheavey 43:81d22f68dfae 324 lcd.printString(" VICTORY! ",2,1);
jamesheavey 47:1d1a827be81b 325 lcd.printString(" CONT = START ",0,4);
jamesheavey 47:1d1a827be81b 326 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 43:81d22f68dfae 327
jamesheavey 13:418a71b24b37 328 lcd.refresh();
jamesheavey 15:b867a6620f96 329
jamesheavey 64:c3426b417ad9 330 wait(0.4);
jamesheavey 64:c3426b417ad9 331
jamesheavey 64:c3426b417ad9 332 lcd.clear();
jamesheavey 64:c3426b417ad9 333
jamesheavey 64:c3426b417ad9 334 sprintf(buffer1,"%2d",breakout.get_score());
jamesheavey 67:c362df66fac9 335 lcd.printString(buffer1,WIDTH/2 - 12,2);
jamesheavey 64:c3426b417ad9 336 lcd.printString(" VICTORY! ",2,1);
jamesheavey 64:c3426b417ad9 337 lcd.printString(" CONT = START ",0,4); // print score here
jamesheavey 64:c3426b417ad9 338 lcd.printString(" MENU = BACK ",0,5);
jamesheavey 64:c3426b417ad9 339 lcd.refresh();
jamesheavey 75:d96b177585aa 340
jamesheavey 64:c3426b417ad9 341 pad.tone(2500.0,0.1);
jamesheavey 64:c3426b417ad9 342
jamesheavey 64:c3426b417ad9 343 lcd.refresh();
jamesheavey 64:c3426b417ad9 344
jamesheavey 64:c3426b417ad9 345 wait(0.4);
jamesheavey 64:c3426b417ad9 346
jamesheavey 43:81d22f68dfae 347 if (pad.check_event(Gamepad::START_PRESSED)) {
jamesheavey 64:c3426b417ad9 348 breakout.set_prev_score(breakout.get_score());
jamesheavey 72:7254d2a8a1cd 349 main_game(tilt,sens);
jamesheavey 43:81d22f68dfae 350 }
jamesheavey 43:81d22f68dfae 351 else if (pad.check_event(Gamepad::BACK_PRESSED)) {
jamesheavey 64:c3426b417ad9 352 breakout.set_prev_score(0);
jamesheavey 49:31eb7807dbd3 353 title_screen();
jamesheavey 43:81d22f68dfae 354 }
jamesheavey 13:418a71b24b37 355 }
jamesheavey 13:418a71b24b37 356 }
jamesheavey 13:418a71b24b37 357
jamesheavey 59:fdc05d5778a6 358 void flash_screen(N5110 &lcd) { // move to engine
jamesheavey 58:a159cd976aca 359 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 360 wait(0.1);
jamesheavey 58:a159cd976aca 361 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 362 wait(0.1);
jamesheavey 58:a159cd976aca 363 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 364 wait(0.1);
jamesheavey 47:1d1a827be81b 365 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 366 wait(0.1);
jamesheavey 58:a159cd976aca 367 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 368 wait(0.1);
jamesheavey 58:a159cd976aca 369 lcd.setBrightness(1);
jamesheavey 58:a159cd976aca 370 wait(0.1);
jamesheavey 58:a159cd976aca 371 lcd.setBrightness(0);
jamesheavey 58:a159cd976aca 372 wait(0.1);
jamesheavey 58:a159cd976aca 373 lcd.setBrightness(1);
jamesheavey 59:fdc05d5778a6 374 }
jamesheavey 59:fdc05d5778a6 375
jamesheavey 59:fdc05d5778a6 376 void countdown() {
jamesheavey 59:fdc05d5778a6 377 Bitmap three(three_data, 48, 84); // assign the 3 sprite data
jamesheavey 59:fdc05d5778a6 378 Bitmap two(two_data, 48, 84); // assign the 2 sprite data
jamesheavey 59:fdc05d5778a6 379 Bitmap one(one_data, 48, 84); // assign the 1 sprite data
jamesheavey 59:fdc05d5778a6 380
jamesheavey 59:fdc05d5778a6 381 lcd.clear();
jamesheavey 59:fdc05d5778a6 382 three.render(lcd, 0, 0); // render the 3
jamesheavey 59:fdc05d5778a6 383 lcd.refresh();
jamesheavey 59:fdc05d5778a6 384 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 385 wait(1); // wait 1 second
jamesheavey 59:fdc05d5778a6 386
jamesheavey 59:fdc05d5778a6 387 lcd.clear();
jamesheavey 59:fdc05d5778a6 388 two.render(lcd, 0, 0); // render 2
jamesheavey 59:fdc05d5778a6 389 lcd.refresh();
jamesheavey 59:fdc05d5778a6 390 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 391 wait(1); // wait 1 second
jamesheavey 59:fdc05d5778a6 392
jamesheavey 59:fdc05d5778a6 393 lcd.clear();
jamesheavey 59:fdc05d5778a6 394 one.render(lcd, 0, 0); // render 1
jamesheavey 59:fdc05d5778a6 395 lcd.refresh();
jamesheavey 59:fdc05d5778a6 396 pad.tone(1000.0,1);
jamesheavey 59:fdc05d5778a6 397 wait(1); // wait 1 second
jamesheavey 58:a159cd976aca 398 }