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