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