FINAL VERSION

Dependencies:   mbed

Committer:
jamesheavey
Date:
Mon May 06 14:15:45 2019 +0000
Revision:
79:70510b0102af
Parent:
78:b523226b7572
Child:
80:f57acdb7121f
cp;

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