
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
Diff: main.cpp
- Revision:
- 16:1f196a0e12be
- Parent:
- 15:5bf3f951d337
- Child:
- 17:2fbe40177b9c
--- a/main.cpp Mon May 18 18:03:43 2020 +0000 +++ b/main.cpp Tue May 19 01:17:31 2020 +0000 @@ -12,6 +12,17 @@ #include "Splash.h" #include "Game.h" +const int highscore_icon [9][15] = { + {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, + {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, + {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, + {1,1,1,1,0,1,0,0,0,1,0,0,0,0,0}, + {1,0,0,1,0,1,0,0,0,1,0,1,1,1,1}, + {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, + {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, + {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, + {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, +}; const int a_button [9][9] = { {0,0,0,1,1,1,0,0,0}, {0,0,1,0,0,0,1,0,0}, @@ -63,18 +74,16 @@ Splash splash(lcd, ball); Game game(lcd, pad, ball); //functions +void init(); void display_menu(); +void how_to(); +void display_settings(); //variables int main() { - lcd.init(); - lcd.setContrast(0.5); - pad.init(); - lcd.backLightOn(); - splash.displayInfo(); - splash.playIntro(); + init(); while (1) { //ball.level_loop(); @@ -83,11 +92,13 @@ wait(0.2); //debounce game.init(); game.play(); + lcd.clear(); lcd.printString("GAME OVER",15,2); lcd.refresh(); wait(2); + pad.reset_buttons(); //to ensure no accidental selection on menu } - if (pad.B_pressed()) { + else if (pad.B_pressed()) { wait(0.2); //debounce while(!pad.B_pressed()) { //Instructions Page @@ -96,25 +107,25 @@ lcd.clear(); } } - if (pad.X_pressed()) { + else if (pad.X_pressed()) { while(!pad.B_pressed()) { - //settings - wait_ms(100); - lcd.refresh(); - lcd.clear(); + display_settings(); } } - if (pad.Y_pressed()) { + else if (pad.Y_pressed()) { lcd.turnOff(); pad.leds(0.0); } - - wait_ms(100); - lcd.refresh(); - lcd.clear(); } } - +void init() { + lcd.init(); + lcd.setContrast(0.5); + pad.init(); + lcd.backLightOn(); + splash.displayInfo(); + splash.playIntro(); +} void display_menu() { splash.drawLogo(13, 0); @@ -126,6 +137,36 @@ 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.drawRect(65, 30, 15, 12, FILL_TRANSPARENT); + int highscore = game.get_highscore(); + char buffer[12]; + sprintf(buffer,"%d",highscore); + lcd.printString(buffer,67,4); lcd.refresh(); wait(0.1); -} \ No newline at end of file + lcd.clear(); +} +void how_to() { + //page 1 - b to exit, buttons on gamepad + //page 2 - a to stop pointer, b to set power + //page 3- tips + //page 4- tips + //page 5- life after 5 points +} +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.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); + lcd.setContrast(pot_1_val); + lcd.refresh(); + wait_ms(100); + lcd.clear(); +} + \ No newline at end of file