James Heavey
/
EL17JH
FINAL VERSION
Diff: main.cpp
- Revision:
- 59:fdc05d5778a6
- Parent:
- 58:a159cd976aca
- Child:
- 60:63d69184ec0a
diff -r a159cd976aca -r fdc05d5778a6 main.cpp --- a/main.cpp Sat May 04 18:43:08 2019 +0000 +++ b/main.cpp Sat May 04 19:09:10 2019 +0000 @@ -39,6 +39,7 @@ void title_screen(); void main_game(bool tilt); void flash_screen(N5110 &lcd); +void countdown(); int prev_score = 0; bool tilt = false; @@ -221,27 +222,7 @@ lcd.setBrightness(1); - Bitmap three(three_data, 48, 84); // assign the 3 sprite data - Bitmap two(two_data, 48, 84); // assign the 2 sprite data - Bitmap one(one_data, 48, 84); // assign the 1 sprite data - - lcd.clear(); - three.render(lcd, 0, 0); // render the 3 - lcd.refresh(); - pad.tone(500.0,0.5); - wait(1); // wait 1 second - - lcd.clear(); - two.render(lcd, 0, 0); // render 2 - lcd.refresh(); - pad.tone(500.0,0.5); - wait(1); // wait 1 second - - lcd.clear(); - one.render(lcd, 0, 0); // render 1 - lcd.refresh(); - pad.tone(1000.0,1); - wait(1); // wait 1 second + countdown(); // run the countdown render(); // first draw the initial frame wait(1.0f/fps); // and wait for one frame period @@ -249,29 +230,29 @@ // game loop - read input, update the game state and render the display while (1) { - breakout.read_input(pad,tilt); - breakout.update(pad); - render(); - if (breakout.check_goal(pad) == true) { + breakout.read_input(pad,tilt); // read input from pad + breakout.update(pad); // update game + render(); // draw new frame + if (breakout.check_goal(pad) == true) { // if life lost flash screen flash_screen(lcd); } - if (pad.check_event(Gamepad::BACK_PRESSED) == true) { + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause pause = !pause; } - while (pause == true) { + while (pause == true) { // if pause is true, display pause screen lcd.clear(); lcd.printString(" PAUSED ",0,2); lcd.refresh(); - if (pad.check_event(Gamepad::BACK_PRESSED) == true) { + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen pause = !pause; } - wait(1.0f/fps); + wait(0.3); } - if (breakout.get_lives() == 0) { - pad.leds_off(); //turns last led off (doesnt run through and update bored so last led doent turn off via lives leds + if (breakout.get_lives() == 0) { // when all lives lost, enter end screen + pad.leds_off(); //turns last led off (doesnt run through and update board so last led doent turn off via lives leds end_screen(); } - if (breakout.get_num_left() == 0) { + if (breakout.get_num_left() == 0) { // when all bricks destroyed, display victory screen victory_screen(); } wait(1.0f/fps); @@ -331,7 +312,7 @@ } } -void flash_screen(N5110 &lcd) { +void flash_screen(N5110 &lcd) { // move to engine lcd.setBrightness(0); wait(0.1); lcd.setBrightness(1); @@ -347,4 +328,28 @@ lcd.setBrightness(0); wait(0.1); lcd.setBrightness(1); +} + +void countdown() { + Bitmap three(three_data, 48, 84); // assign the 3 sprite data + Bitmap two(two_data, 48, 84); // assign the 2 sprite data + Bitmap one(one_data, 48, 84); // assign the 1 sprite data + + lcd.clear(); + three.render(lcd, 0, 0); // render the 3 + lcd.refresh(); + pad.tone(500.0,0.5); + wait(1); // wait 1 second + + lcd.clear(); + two.render(lcd, 0, 0); // render 2 + lcd.refresh(); + pad.tone(500.0,0.5); + wait(1); // wait 1 second + + lcd.clear(); + one.render(lcd, 0, 0); // render 1 + lcd.refresh(); + pad.tone(1000.0,1); + wait(1); // wait 1 second } \ No newline at end of file