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