James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Committer:
jamesheavey
Date:
Mon May 06 23:43:28 2019 +0000
Revision:
95:09550aeca8b9
Parent:
94:8fa117200f6b
Child:
96:c30e110c0a93
FIXED THE MEMORY ERROR!!!!!

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 95:09550aeca8b9 36 Bitmap breakwhite(breakwhite_data, 48, 84); // assign the title screen sprites
jamesheavey 95:09550aeca8b9 37 Bitmap breakblack(breakblack_data, 48, 84);
jamesheavey 95:09550aeca8b9 38 Bitmap arrowup(arrowup_data, 5, 7); // assign the arrow up sprite data
jamesheavey 95:09550aeca8b9 39 Bitmap arrowdown(arrowdown_data, 5, 7); // assign the arrow down sprite data
jamesheavey 95:09550aeca8b9 40
jamesheavey 47:1d1a827be81b 41 bool tilt = false;
jamesheavey 72:7254d2a8a1cd 42 float sens = 0.5; // default sens
jamesheavey 0:7d4d2023ed9c 43
jamesheavey 0:7d4d2023ed9c 44 ///////////// functions ////////////////
jamesheavey 79:70510b0102af 45
jamesheavey 0:7d4d2023ed9c 46 int main()
jamesheavey 91:c01a736fb0d9 47 {
jamesheavey 58:a159cd976aca 48 init(); // initialise the gamepad
jamesheavey 58:a159cd976aca 49 title_screen(); // run the title screen
jamesheavey 0:7d4d2023ed9c 50 }
jamesheavey 0:7d4d2023ed9c 51
jamesheavey 0:7d4d2023ed9c 52 // initialies all classes and libraries
jamesheavey 56:f9e586348e0b 53 void init()
jamesheavey 0:7d4d2023ed9c 54 {
jamesheavey 91:c01a736fb0d9 55 // need to initialise LCD and Gamepad
jamesheavey 0:7d4d2023ed9c 56 lcd.init();
jamesheavey 0:7d4d2023ed9c 57 pad.init();
jamesheavey 72:7254d2a8a1cd 58 breakout.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); // init the objects
jamesheavey 0:7d4d2023ed9c 59
jamesheavey 0:7d4d2023ed9c 60 }
jamesheavey 0:7d4d2023ed9c 61
jamesheavey 0:7d4d2023ed9c 62 // this function draws each frame on the LCD
jamesheavey 0:7d4d2023ed9c 63 void render()
jamesheavey 0:7d4d2023ed9c 64 {
jamesheavey 0:7d4d2023ed9c 65 // clear screen, re-draw and refresh
jamesheavey 91:c01a736fb0d9 66 lcd.clear();
jamesheavey 26:25eea19c5fbe 67 breakout.draw(lcd);
jamesheavey 0:7d4d2023ed9c 68 lcd.refresh();
jamesheavey 0:7d4d2023ed9c 69 }
jamesheavey 0:7d4d2023ed9c 70
jamesheavey 91:c01a736fb0d9 71 void title_screen()
jamesheavey 91:c01a736fb0d9 72 {
jamesheavey 58:a159cd976aca 73 tilt = false; // reset the tilt variable so that on start, joystick is default
jamesheavey 91:c01a736fb0d9 74
jamesheavey 58:a159cd976aca 75 lcd.clear();
jamesheavey 91:c01a736fb0d9 76
jamesheavey 58:a159cd976aca 77 breakblack.render(lcd, 0, 0); // render the first frame
jamesheavey 58:a159cd976aca 78 lcd.refresh();
jamesheavey 58:a159cd976aca 79 pad.leds_off();
jamesheavey 58:a159cd976aca 80 wait(0.5);
jamesheavey 91:c01a736fb0d9 81
jamesheavey 58:a159cd976aca 82 while (pad.check_event(Gamepad::START_PRESSED) == false) { // while start is not pressed alternate sprites
jamesheavey 91:c01a736fb0d9 83
jamesheavey 58:a159cd976aca 84 lcd.clear();
jamesheavey 91:c01a736fb0d9 85
jamesheavey 58:a159cd976aca 86 breakwhite.render(lcd, 0, 0);
jamesheavey 58:a159cd976aca 87 lcd.refresh();
jamesheavey 58:a159cd976aca 88 pad.leds_on();
jamesheavey 58:a159cd976aca 89 wait(0.5);
jamesheavey 91:c01a736fb0d9 90
jamesheavey 58:a159cd976aca 91 lcd.clear();
jamesheavey 91:c01a736fb0d9 92
jamesheavey 58:a159cd976aca 93 breakblack.render(lcd, 0, 0);
jamesheavey 58:a159cd976aca 94 lcd.refresh();
jamesheavey 58:a159cd976aca 95 pad.leds_off();
jamesheavey 58:a159cd976aca 96 wait(0.5);
jamesheavey 58:a159cd976aca 97 }
jamesheavey 91:c01a736fb0d9 98
jamesheavey 58:a159cd976aca 99 pad.tone(750.0,0.3);
jamesheavey 58:a159cd976aca 100 wait(0.2);
jamesheavey 58:a159cd976aca 101 main_menu(); // load main menu
jamesheavey 58:a159cd976aca 102 }
jamesheavey 58:a159cd976aca 103
jamesheavey 58:a159cd976aca 104
jamesheavey 91:c01a736fb0d9 105 void main_menu()
jamesheavey 91:c01a736fb0d9 106 {
jamesheavey 91:c01a736fb0d9 107
jamesheavey 50:3da51f34e253 108 lcd.clear();
jamesheavey 73:54ab819609bc 109 lcd.printString(" START ",0,1); // start with default as joystick
jamesheavey 73:54ab819609bc 110 lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt
jamesheavey 73:54ab819609bc 111 lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff
jamesheavey 91:c01a736fb0d9 112 lcd.refresh();
jamesheavey 56:f9e586348e0b 113 wait(0.3);
jamesheavey 91:c01a736fb0d9 114
jamesheavey 73:54ab819609bc 115 int pointer = 1;
jamesheavey 91:c01a736fb0d9 116
jamesheavey 91:c01a736fb0d9 117 while (pad.check_event(Gamepad::A_PRESSED) == false) {
jamesheavey 53:8e3da0b58fe9 118 lcd.clear();
jamesheavey 73:54ab819609bc 119 lcd.printString(" START ",0,1); // start with default as joystick
jamesheavey 73:54ab819609bc 120 lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt
jamesheavey 73:54ab819609bc 121 lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff
jamesheavey 56:f9e586348e0b 122 lcd.printString(" >",0,pointer);
jamesheavey 91:c01a736fb0d9 123 lcd.refresh();
jamesheavey 53:8e3da0b58fe9 124 wait(0.1);
jamesheavey 73:54ab819609bc 125 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 126 pointer -= 1;
jamesheavey 53:8e3da0b58fe9 127 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 128 wait(0.1);
jamesheavey 73:54ab819609bc 129 } 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 130 pointer += 1;
jamesheavey 53:8e3da0b58fe9 131 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 132 wait(0.1);
jamesheavey 50:3da51f34e253 133 }
jamesheavey 91:c01a736fb0d9 134
jamesheavey 50:3da51f34e253 135 }
jamesheavey 73:54ab819609bc 136 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 137 pad.tone(750.0,0.3);
jamesheavey 72:7254d2a8a1cd 138 main_game(tilt,sens);
jamesheavey 91:c01a736fb0d9 139 } else if (pointer == 2) { // if SETTINGS was selected, enter the settings menu
jamesheavey 56:f9e586348e0b 140 pad.tone(750.0,0.3);
jamesheavey 51:9d5c10a88b22 141 settings();
jamesheavey 91:c01a736fb0d9 142 } else if (pointer == 3) { // if HOW TO PLAY WAS SELECTED, display instructions on how to play
jamesheavey 56:f9e586348e0b 143 pad.tone(750.0,0.3);
jamesheavey 51:9d5c10a88b22 144 how_to_play();
jamesheavey 51:9d5c10a88b22 145 }
jamesheavey 50:3da51f34e253 146 }
jamesheavey 50:3da51f34e253 147
jamesheavey 91:c01a736fb0d9 148 void settings()
jamesheavey 91:c01a736fb0d9 149 {
jamesheavey 50:3da51f34e253 150
jamesheavey 50:3da51f34e253 151 lcd.clear();
jamesheavey 72:7254d2a8a1cd 152 lcd.printString(" JOYSTICK ",0,1); // choose joystick
jamesheavey 72:7254d2a8a1cd 153 lcd.printString(" TILT ",0,2); // choose tilt
jamesheavey 72:7254d2a8a1cd 154 lcd.printString("SENS :",0,4);
jamesheavey 72:7254d2a8a1cd 155 lcd.drawRect(42,30, 40,10,FILL_TRANSPARENT);
jamesheavey 72:7254d2a8a1cd 156 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 157 // the sens can only change via pot when the pointer is on the right pointer
jamesheavey 91:c01a736fb0d9 158 lcd.refresh();
jamesheavey 75:d96b177585aa 159 wait(0.4);
jamesheavey 91:c01a736fb0d9 160
jamesheavey 72:7254d2a8a1cd 161 int pointer = 1;
jamesheavey 91:c01a736fb0d9 162
jamesheavey 58:a159cd976aca 163 while (pad.check_event(Gamepad::B_PRESSED) == false) { // while B is not pressed to return to main menu
jamesheavey 53:8e3da0b58fe9 164 lcd.clear();
jamesheavey 72:7254d2a8a1cd 165 lcd.printString(" JOYSTICK ",0,1); // choose joystick
jamesheavey 72:7254d2a8a1cd 166 lcd.printString(" TILT ",0,2); // choose tilt
jamesheavey 72:7254d2a8a1cd 167 lcd.printString("SENS :",0,4);
jamesheavey 56:f9e586348e0b 168 lcd.printString(" >",0,pointer);
jamesheavey 72:7254d2a8a1cd 169 lcd.drawRect(42,30, 40,10,FILL_TRANSPARENT);
jamesheavey 72:7254d2a8a1cd 170 lcd.drawRect(42,30,40 * pad.read_pot() + 1,10,FILL_BLACK); // have it so it fills half the transparent one (default position)
jamesheavey 91:c01a736fb0d9 171 lcd.refresh();
jamesheavey 53:8e3da0b58fe9 172 wait(0.1);
jamesheavey 72:7254d2a8a1cd 173 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 174 pointer -= 1;
jamesheavey 53:8e3da0b58fe9 175 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 176 wait(0.1);
jamesheavey 72:7254d2a8a1cd 177 } 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 178 pointer += 1;
jamesheavey 53:8e3da0b58fe9 179 pad.tone(750.0,0.3);
jamesheavey 53:8e3da0b58fe9 180 wait(0.1);
jamesheavey 50:3da51f34e253 181 }
jamesheavey 91:c01a736fb0d9 182
jamesheavey 58:a159cd976aca 183 if (pad.check_event(Gamepad::A_PRESSED)) { // if A is pressed, switch the tilt option accordingly
jamesheavey 56:f9e586348e0b 184 pad.tone(750.0,0.3);
jamesheavey 56:f9e586348e0b 185 wait(0.1);
jamesheavey 74:dfb1d693d8e3 186 if (pointer == 1) { // if A is pressed on JOYSTICK, tilt = false
jamesheavey 57:d498dd835cfc 187 tilt = false;
jamesheavey 91:c01a736fb0d9 188 } else if (pointer == 2) { // if A is pressed on TILT, tilt == true
jamesheavey 57:d498dd835cfc 189 tilt = true;
jamesheavey 57:d498dd835cfc 190 }
jamesheavey 58:a159cd976aca 191 }
jamesheavey 91:c01a736fb0d9 192
jamesheavey 58:a159cd976aca 193 if (pad.check_event(Gamepad::B_PRESSED)) { // when B is pressed return to main menu
jamesheavey 56:f9e586348e0b 194 pad.tone(750.0,0.3);
jamesheavey 72:7254d2a8a1cd 195 sens = pad.read_pot() + 0.5f;
jamesheavey 91:c01a736fb0d9 196 wait(0.3);
jamesheavey 50:3da51f34e253 197 main_menu();
jamesheavey 16:1761dfe801af 198 }
jamesheavey 0:7d4d2023ed9c 199 }
jamesheavey 10:9f445faa892c 200 }
jamesheavey 10:9f445faa892c 201
jamesheavey 91:c01a736fb0d9 202 void how_to_play()
jamesheavey 91:c01a736fb0d9 203 {
jamesheavey 84:6483503a72fc 204 lcd.clear();
jamesheavey 84:6483503a72fc 205 lcd.printString(" B = LASER ",0,0);
jamesheavey 84:6483503a72fc 206 lcd.printString(" START = PAUSE ",0,1);
jamesheavey 84:6483503a72fc 207 lcd.printString(" DESTROY ALL ",0,2);
jamesheavey 84:6483503a72fc 208 lcd.printString(" BRICKS ",0,3);
jamesheavey 91:c01a736fb0d9 209 arrowdown.render(lcd, 38, 43);
jamesheavey 84:6483503a72fc 210 lcd.refresh();
jamesheavey 84:6483503a72fc 211 wait(0.4);
jamesheavey 58:a159cd976aca 212 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 91:c01a736fb0d9 213
jamesheavey 91:c01a736fb0d9 214 if (pad.check_event(Gamepad::R_PRESSED)) {
jamesheavey 84:6483503a72fc 215 lcd.clear();
jamesheavey 84:6483503a72fc 216 lcd.printString(" CONTINUE TO ",0,2);
jamesheavey 84:6483503a72fc 217 lcd.printString("INCREASE SCORE. ",0,3);
jamesheavey 91:c01a736fb0d9 218 arrowup.render(lcd, 38, 0);
jamesheavey 91:c01a736fb0d9 219 lcd.refresh();
jamesheavey 84:6483503a72fc 220 wait(0.1);
jamesheavey 84:6483503a72fc 221 }
jamesheavey 91:c01a736fb0d9 222 if (pad.check_event(Gamepad::L_PRESSED)) {
jamesheavey 84:6483503a72fc 223 lcd.clear();
jamesheavey 84:6483503a72fc 224 lcd.printString(" B = LASER ",0,0);
jamesheavey 84:6483503a72fc 225 lcd.printString(" START = PAUSE ",0,1);
jamesheavey 84:6483503a72fc 226 lcd.printString(" DESTROY ALL ",0,2);
jamesheavey 84:6483503a72fc 227 lcd.printString(" BRICKS ",0,3);
jamesheavey 91:c01a736fb0d9 228 arrowdown.render(lcd, 38, 43);
jamesheavey 84:6483503a72fc 229 lcd.refresh();
jamesheavey 84:6483503a72fc 230 wait(0.1);
jamesheavey 84:6483503a72fc 231 }
jamesheavey 50:3da51f34e253 232 }
jamesheavey 84:6483503a72fc 233 wait(0.3);
jamesheavey 58:a159cd976aca 234 main_menu(); // when B is pressed, the loop is exited and main menu is entered once again
jamesheavey 58:a159cd976aca 235 }
jamesheavey 58:a159cd976aca 236
jamesheavey 58:a159cd976aca 237
jamesheavey 91:c01a736fb0d9 238 void main_game(bool tilt, float sens)
jamesheavey 91:c01a736fb0d9 239 {
jamesheavey 58:a159cd976aca 240 int fps = 8; // frames per second
jamesheavey 58:a159cd976aca 241 bool pause = false; // set pause screen to false
jamesheavey 91:c01a736fb0d9 242
jamesheavey 58:a159cd976aca 243 lcd.setBrightness(1);
jamesheavey 91:c01a736fb0d9 244
jamesheavey 59:fdc05d5778a6 245 countdown(); // run the countdown
jamesheavey 91:c01a736fb0d9 246
jamesheavey 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 302 lcd.refresh();
jamesheavey 15:b867a6620f96 303 pad.tone(750.0,0.3);
jamesheavey 15:b867a6620f96 304 wait(0.4);
jamesheavey 91:c01a736fb0d9 305
jamesheavey 15:b867a6620f96 306 pad.tone(300.0,0.3);
jamesheavey 15:b867a6620f96 307 wait(0.4);
jamesheavey 91:c01a736fb0d9 308
jamesheavey 91:c01a736fb0d9 309 while (pad.check_event(Gamepad::START_PRESSED) == false) {
jamesheavey 10:9f445faa892c 310 lcd.clear();
jamesheavey 91:c01a736fb0d9 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 91:c01a736fb0d9 315
jamesheavey 64:c3426b417ad9 316 wait(0.4);
jamesheavey 91:c01a736fb0d9 317
jamesheavey 64:c3426b417ad9 318 lcd.clear();
jamesheavey 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 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 91:c01a736fb0d9 345
jamesheavey 22:fa2e0b58043a 346 pad.tone(2500.0,0.1);
jamesheavey 22:fa2e0b58043a 347 wait(0.2);
jamesheavey 91:c01a736fb0d9 348
jamesheavey 15:b867a6620f96 349 pad.tone(4000.0,0.6);
jamesheavey 15:b867a6620f96 350 wait(0.6);
jamesheavey 91:c01a736fb0d9 351 while (pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED) == false) {
jamesheavey 13:418a71b24b37 352 lcd.clear();
jamesheavey 91:c01a736fb0d9 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 91:c01a736fb0d9 359
jamesheavey 64:c3426b417ad9 360 wait(0.4);
jamesheavey 91:c01a736fb0d9 361
jamesheavey 64:c3426b417ad9 362 lcd.clear();
jamesheavey 91:c01a736fb0d9 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 91:c01a736fb0d9 370
jamesheavey 64:c3426b417ad9 371 pad.tone(2500.0,0.1);
jamesheavey 64:c3426b417ad9 372
jamesheavey 64:c3426b417ad9 373 lcd.refresh();
jamesheavey 91:c01a736fb0d9 374
jamesheavey 64:c3426b417ad9 375 wait(0.4);
jamesheavey 91:c01a736fb0d9 376
jamesheavey 43:81d22f68dfae 377 if (pad.check_event(Gamepad::START_PRESSED)) {
jamesheavey 64:c3426b417ad9 378 breakout.set_prev_score(breakout.get_score());
jamesheavey 91:c01a736fb0d9 379 main_game(tilt,sens);
jamesheavey 91:c01a736fb0d9 380 } else if (pad.check_event(Gamepad::BACK_PRESSED)) {
jamesheavey 64:c3426b417ad9 381 breakout.set_prev_score(0);
jamesheavey 49:31eb7807dbd3 382 title_screen();
jamesheavey 43:81d22f68dfae 383 }
jamesheavey 13:418a71b24b37 384 }
jamesheavey 13:418a71b24b37 385 }
jamesheavey 13:418a71b24b37 386
jamesheavey 91:c01a736fb0d9 387 void flash_screen(N5110 &lcd) // move to engine
jamesheavey 91:c01a736fb0d9 388 {
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 91:c01a736fb0d9 406 void countdown()
jamesheavey 91:c01a736fb0d9 407 {
jamesheavey 59:fdc05d5778a6 408 Bitmap three(three_data, 48, 84); // assign the 3 sprite data
jamesheavey 59:fdc05d5778a6 409 Bitmap two(two_data, 48, 84); // assign the 2 sprite data
jamesheavey 59:fdc05d5778a6 410 Bitmap one(one_data, 48, 84); // assign the 1 sprite data
jamesheavey 91:c01a736fb0d9 411
jamesheavey 59:fdc05d5778a6 412 lcd.clear();
jamesheavey 59:fdc05d5778a6 413 three.render(lcd, 0, 0); // render the 3
jamesheavey 59:fdc05d5778a6 414 lcd.refresh();
jamesheavey 59:fdc05d5778a6 415 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 416 wait(1); // wait 1 second
jamesheavey 91:c01a736fb0d9 417
jamesheavey 59:fdc05d5778a6 418 lcd.clear();
jamesheavey 59:fdc05d5778a6 419 two.render(lcd, 0, 0); // render 2
jamesheavey 59:fdc05d5778a6 420 lcd.refresh();
jamesheavey 59:fdc05d5778a6 421 pad.tone(500.0,0.5);
jamesheavey 59:fdc05d5778a6 422 wait(1); // wait 1 second
jamesheavey 91:c01a736fb0d9 423
jamesheavey 59:fdc05d5778a6 424 lcd.clear();
jamesheavey 59:fdc05d5778a6 425 one.render(lcd, 0, 0); // render 1
jamesheavey 59:fdc05d5778a6 426 lcd.refresh();
jamesheavey 59:fdc05d5778a6 427 pad.tone(1000.0,1);
jamesheavey 59:fdc05d5778a6 428 wait(1); // wait 1 second
jamesheavey 58:a159cd976aca 429 }