James Heavey
/
EL17JH
FINAL VERSION
Diff: main.cpp
- Revision:
- 99:d8f1570faa05
- Parent:
- 98:2ce2c666266b
- Child:
- 100:9842813b7131
--- a/main.cpp Tue May 07 15:54:04 2019 +0000 +++ b/main.cpp Tue May 07 16:56:39 2019 +0000 @@ -5,7 +5,7 @@ #include "BreakoutEngine.h" #include "Bitmap.h" #include "Sprites.h" -#include "SDFileSystem.h" +//#include "SDFileSystem.h" //#include "Menus.h" //#include "Game.h" /////////////// structs ///////////////// @@ -20,8 +20,8 @@ N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; BreakoutEngine breakout; -SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS -Serial serial(USBTX, USBRX); // for PC debug +//SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS +//Serial serial(USBTX, USBRX); // for PC debug ///////////// prototypes /////////////// @@ -37,7 +37,7 @@ void main_game(bool tilt,float sens); void flash_screen(N5110 &lcd); void countdown(); -void save_hi_score(int hi_score) +void save_hi_score(int hi_score); int get_hi_score(); Bitmap breakwhite(breakwhite_data, 48, 84); // assign the title screen sprites @@ -50,6 +50,7 @@ bool tilt = false; float sens = 0.5; // default sens +int number_of_frames = 0; ///////////// functions //////////////// @@ -113,9 +114,8 @@ void main_menu() { - lcd.clear(); - lcd.printString(" START ",0,1); // start with default as joystick + lcd.printString(" START ",0,1); // start game with default as joystick lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff lcd.refresh(); @@ -125,7 +125,7 @@ while (pad.check_event(Gamepad::A_PRESSED) == false) { lcd.clear(); - lcd.printString(" START ",0,1); // start with default as joystick + lcd.printString(" START ",0,1); // start game with default as joystick lcd.printString(" SETTINGS ",0,2); // choose between joystick and tilt lcd.printString(" HOW TO PLAY ",0,3); // brief text on how to do stuff lcd.printString(" >",0,pointer); @@ -140,15 +140,17 @@ pad.tone(750.0,0.3); wait(0.1); } + //printf("Pointer 1 = %d",pointer); } if (pointer == 1) { // if START was selected on exit of the while loop, run main game with the appropriate tilt/joystick setting pad.tone(750.0,0.3); + number_of_frames = 0; main_game(tilt,sens); } else if (pointer == 2) { // if SETTINGS was selected, enter the settings menu pad.tone(750.0,0.3); settings(); - } else if (pointer == 3) { // if HOW TO PLAY WAS SELECTED, display instructions on how to play + } else if (pointer == 3) { // if HOW TO PLAY was selected, display instructions on how to play pad.tone(750.0,0.3); how_to_play(); } @@ -156,14 +158,12 @@ void settings() { - lcd.clear(); lcd.printString(" JOYSTICK ",0,1); // choose joystick lcd.printString(" TILT ",0,2); // choose tilt lcd.printString("SENS :",0,4); lcd.drawRect(42,30, 40,10,FILL_TRANSPARENT); - lcd.drawRect(42,30,40 * pad.read_pot() + 1,10,FILL_BLACK); // have it so it fills half the transparent one (default position) - // the sens can only change via pot when the pointer is on the right pointer + lcd.drawRect(42,30,40 * pad.read_pot() + 1,10,FILL_BLACK); // represents the sensitivity which is changed by turning the pot lcd.refresh(); wait(0.4); @@ -202,9 +202,11 @@ if (pad.check_event(Gamepad::B_PRESSED)) { // when B is pressed return to main menu pad.tone(750.0,0.3); sens = pad.read_pot() + 0.5f; + //printf("Sensitivity = %d",sens); wait(0.3); main_menu(); } + //printf("Pointer 2 = %d",pointer); } } @@ -248,6 +250,7 @@ { int fps = 8; // frames per second bool pause = false; // set pause screen to false + //printf("Pause = %d",pointer); lcd.setBrightness(1); @@ -276,31 +279,35 @@ lcd.printString(" START = PLAY",0,3); lcd.printString(" BACK = MENU",0,4); lcd.refresh(); - if (pad.check_event(Gamepad::START_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen + if (pad.check_event(Gamepad::START_PRESSED) == true) { // if START pressed, toggle pause, leaving pause screen pause = !pause; } - if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, toggle pause, leaving pause screen + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, return to the title screen + breakout.set_mult_one(); // reset multiplier + breakout.set_prev_score(0); + breakout.reset_game(); //reset game to initial positions title_screen(); } } if (breakout.get_lives() == 0) { // when all lives lost, enter loss screen pad.leds_off(); //turns last led off (doesnt run through and update board so last led doent turn off via lives leds - breakout.reset_game(); - breakout.set_mult_zero(); - loss_screen(); + breakout.set_mult_one(); // reset multiplier + breakout.reset_game(); // return game to initial positions + loss_screen(); } if (breakout.get_num_left() == 0) { // when all bricks destroyed, display victory screen - breakout.reset_game(); - breakout.inc_mult(); + breakout.reset_game(); // return game to initial positions + breakout.inc_mult(); // increment multiplier victory_screen(); } + number_of_frames ++; // track the number of frames passed to add to the score (inversely proportional) wait(1.0f/fps); } } -void loss_screen() +void loss_screen() // loss screen when lives of paddle == 0 { lcd.clear(); char buffer1[14]; @@ -341,10 +348,26 @@ void victory_screen() { + int bonus = NULL; + + if (breakout.get_score()/2 - ((breakout.get_score()/2) * number_of_frames)/720 > 0) { // beat within 90 seconds and you get a bonus + bonus = breakout.get_score()/2 - ((breakout.get_score()/2) * number_of_frames)/720; + } + else { + bonus = 0; + } + lcd.clear(); + char buffer1[14]; sprintf(buffer1,"%2d",breakout.get_score()); lcd.printString(buffer1,WIDTH/2 - 12,2); + + char buffer2[14]; + sprintf(buffer2,"%2d",bonus); + lcd.printString(buffer2,WIDTH/2 + 8,3); + lcd.printString(" BONUS: ",2,3); + lcd.printString(" VICTORY! ",2,1); lcd.printString(" CONT = START ",0,4); // print score here lcd.printString(" MENU = BACK ",0,5); @@ -357,6 +380,7 @@ pad.tone(4000.0,0.6); wait(0.6); + while (pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED) == false) { lcd.clear(); @@ -370,8 +394,15 @@ lcd.clear(); + char buffer1[14]; sprintf(buffer1,"%2d",breakout.get_score()); lcd.printString(buffer1,WIDTH/2 - 12,2); + + char buffer2[14]; + sprintf(buffer2,"%2d",bonus); + lcd.printString(buffer2,WIDTH/2 + 8,3); + lcd.printString(" BONUS:",2,3); + lcd.printString(" VICTORY! ",2,1); lcd.printString(" CONT = START ",0,4); // print score here lcd.printString(" MENU = BACK ",0,5); @@ -384,10 +415,12 @@ wait(0.4); if (pad.check_event(Gamepad::START_PRESSED)) { - breakout.set_prev_score(breakout.get_score()); + breakout.set_prev_score(breakout.get_score() + bonus); + number_of_frames = 0; main_game(tilt,sens); } else if (pad.check_event(Gamepad::BACK_PRESSED)) { breakout.set_prev_score(0); + number_of_frames = 0; title_screen(); } } @@ -432,7 +465,7 @@ pad.tone(1000.0,1); wait(1); // wait 1 second } - +/* void save_hi_score(int hi_score) { serial.baud(115200); // full-speed! @@ -460,4 +493,5 @@ fclose(fp); // ensure you close the file after reading } return stored_hi_score; -} \ No newline at end of file +} +*/ \ No newline at end of file