
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
Diff: main.cpp
- Revision:
- 25:467d8fd0fec4
- Parent:
- 23:ad9ac069e751
- Child:
- 27:1a3504a9d1b9
--- a/main.cpp Mon May 25 13:19:11 2020 +0000 +++ b/main.cpp Mon May 25 18:25:00 2020 +0000 @@ -22,12 +22,14 @@ Splash splash(lcd, ball); Game game(lcd, pad, ball); Instructions instruction(lcd, pad, ball, game); + //functions void init(); void display_menu(); void game_loop(); void how_to(); void display_settings(); + //variables int page = 1; @@ -36,16 +38,17 @@ while (1) { //ball.level_loop(); display_menu(); - page = 1; + instruction.init(); if (pad.A_pressed()) { game_loop(); } else if (pad.B_pressed()) { - wait(0.2); //debounce - while(!pad.B_pressed()) {how_to();} + wait(0.3); //debounce + while (!pad.B_pressed()) { how_to(); } + wait(0.3); pad.reset_buttons(); - wait(0.2); } else if (pad.X_pressed()) { - while(!pad.B_pressed()) { display_settings();} + while (!pad.B_pressed()) { display_settings(); } + wait(0.3); pad.reset_buttons(); } else if (pad.Y_pressed()) { lcd.turnOff(); @@ -62,24 +65,24 @@ splash.displayInfo(); splash.playIntro(); game.init(); -} +} void display_menu() { splash.drawLogo(13, 0); lcd.printString("Play", 2, 2); lcd.printString("How-To?", 2, 3); lcd.printString("Settings", 2, 4); lcd.printString("Exit", 2, 5); - lcd.drawSprite(28, 15, 9, 9, (int*) a_button); - lcd.drawSprite(45, 23, 9, 9, (int*) b_button); - lcd.drawSprite(52, 31, 9, 9, (int*) x_button); - lcd.drawSprite(28, 39, 9, 9, (int*) y_button); + lcd.drawSprite(28, 15, 9, 9, (int * ) a_button); + lcd.drawSprite(45, 23, 9, 9, (int * ) b_button); + lcd.drawSprite(52, 31, 9, 9, (int * ) x_button); + lcd.drawSprite(28, 39, 9, 9, (int * ) y_button); //highscore - lcd.drawSprite(65, 21, 9 , 15, (int *)highscore_icon); + lcd.drawSprite(65, 21, 9, 15, (int * ) highscore_icon); lcd.drawRect(65, 30, 15, 12, FILL_TRANSPARENT); int highscore = game.get_highscore(); char buffer[12]; - sprintf(buffer,"%d",highscore); - lcd.printString(buffer,67,4); + sprintf(buffer, "%d", highscore); + lcd.printString(buffer, 67, 4); lcd.refresh(); wait(0.1); lcd.clear(); @@ -89,7 +92,7 @@ wait(0.2); //debounce game.play(); lcd.clear(); - lcd.printString("GAME OVER",15,2); + lcd.printString("GAME OVER", 15, 2); lcd.refresh(); game.playGoalSound(3); wait(2); @@ -97,26 +100,32 @@ } void how_to() { pad.leds(0.0); - if(pad.get_direction() == N) { page--; } - else if (pad.get_direction() == S || page == 3 || page == 4) { page++; } - if(page > 7) {page = 7;} - if(page < 1) {page = 1;} + if (pad.get_direction() == N) { + page--; + } else if (pad.get_direction() == S || page == 3 || page == 4) { + page++; + } + if (page > 7) { + page = 7; + } + if (page < 1) { + page = 1; + } instruction.set_page(page); instruction.display(); wait(0.2); } void display_settings() { - lcd.printString("Settings",20,0); - lcd.printString("Set Contrast",0,1); - lcd.printString("using Pot 1",0,2); - lcd.printString("Hit B to Exit",0,5); + lcd.printString("Settings", 20, 0); + lcd.printString("Set Contrast", 0, 1); + lcd.printString("using Pot 1", 0, 2); + lcd.printString("Hit B to Exit", 0, 5); lcd.drawRect(0, 24, 84, 8, FILL_TRANSPARENT); float pot_1_val = pad.read_pot1(); - printf("POT 1 = %.2f \n",pot_1_val); - lcd.drawRect(0, 24, (int)(84*pot_1_val), 8, FILL_BLACK); + printf("POT 1 = %.2f \n", pot_1_val); + lcd.drawRect(0, 24, (int)(84 * pot_1_val), 8, FILL_BLACK); lcd.setContrast(pot_1_val); lcd.refresh(); wait_ms(100); lcd.clear(); -} - \ No newline at end of file +} \ No newline at end of file