
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
Diff: main.cpp
- Revision:
- 28:215e8327d4e6
- Parent:
- 27:1a3504a9d1b9
- Child:
- 29:532e5c371be4
--- a/main.cpp Mon May 25 19:52:37 2020 +0000 +++ b/main.cpp Tue May 26 14:45:02 2020 +0000 @@ -1,8 +1,12 @@ /* -Shoot -ELEC2645 Project -EL18KK -201267448 +ELEC2645 Embedded Systems Project +School of Electronic & Electrical Engineering +University of Leeds +Name: Kaif Kutchwala +Username: el18kk +Student ID Number: 201267448 +Date: May 2020 +Game: Shoot! */ #include "mbed.h" @@ -38,25 +42,26 @@ while (1) { //ball.level_loop(); display_menu(); - page = 1; + page = 1; //reset instructions page if (pad.A_pressed()) { - game_loop(); + game_loop(); //if A is pressed, play game } else if (pad.B_pressed()) { wait(0.3); //debounce - while (!pad.B_pressed()) { how_to(); } + while (!pad.B_pressed()) { how_to(); } //if B, show instructions wait(0.3); pad.reset_buttons(); + pad.leds(0.0); } else if (pad.X_pressed()) { - while (!pad.B_pressed()) { display_settings(); } + while (!pad.B_pressed()) { display_settings(); } // if C, settings wait(0.3); pad.reset_buttons(); - } else if (pad.Y_pressed()) { + } else if (pad.Y_pressed()) { // if Y, turn off lcd and leds lcd.turnOff(); pad.leds(0.0); } } } -void init() { +void init() { //initialise all objects, display splash screen and intro run_all_tests(); lcd.init(); pad.init(); @@ -76,7 +81,7 @@ 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 + // displaying highscore lcd.drawSprite(65, 21, 9, 15, (int * ) highscore_icon); lcd.drawRect(65, 30, 15, 12, FILL_TRANSPARENT); int highscore = game.get_highscore(); @@ -88,13 +93,13 @@ lcd.clear(); } void game_loop() { - game.init(); + game.init(); //initialise wait(0.2); //debounce - game.play(); - lcd.clear(); + game.play(); //play game + lcd.clear(); //clear screen once game is over and display apt message lcd.printString("GAME OVER", 15, 2); lcd.refresh(); - game.playGoalSound(3); + game.playGoalSound(3); // game over sound effect wait(2); pad.reset_buttons(); //to ensure no accidental selection on menu } @@ -103,16 +108,16 @@ if (pad.get_direction() == N) { page--; } else if (pad.get_direction() == S || page == 3 || page == 4) { - page++; + page++; //pages 3 and 4 don't need scrolling so increase page number } if (page > 7) { - page = 7; + page = 7; //only 7 pages } if (page < 1) { page = 1; } instruction.set_page(page); - instruction.display(); + instruction.display(); //display page wait(0.2); } void display_settings() { @@ -121,10 +126,11 @@ 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); + float pot_1_val = pad.read_pot1(); // read pot 1 value + //printf("POT 1 = %.2f \n", pot_1_val); + //fill bar proportionally to pot 1 value + lcd.drawRect(0, 24, (int)(84 * pot_1_val), 8, FILL_BLACK); + lcd.setContrast(pot_1_val); //set contrast using pot 1 value lcd.refresh(); wait_ms(100); lcd.clear();