My ELEC2645 project. Nikollao Sulollari. 200804685
Dependencies: N5110 SoftPWM mbed
Fork of Treasure_Hunt by
Diff: main.h
- Revision:
- 13:359d3aa66352
- Parent:
- 11:53caf3d944a9
- Child:
- 14:91ae0afe9037
--- a/main.h Thu Apr 28 16:29:06 2016 +0000 +++ b/main.h Thu Apr 28 22:04:15 2016 +0000 @@ -289,7 +289,8 @@ volatile int tries = 0;/*!< counts the number of trials */ volatile int n;/*!< number of pixels overlapping */ -//int pixels[84][48]; + +volatile int game_speed; int reset = 0; /*!< used to save current level of difficulty */ @@ -595,12 +596,12 @@ updateJoystick(); lcd.clear(); - lcd.printString("Start Game",0,0); + lcd.printString("Start Game",0,0); ///print the main menu lcd.printString("Settings",0,2); lcd.printString("Exit",0,4); //lcd.drawCircle(70,4,2,1); - switch (joystick.direction) { + switch (joystick.direction) { ///check the direction of joystick case UP: option--; break; @@ -615,7 +616,7 @@ option = 0; } - if (option == 0) { + if (option == 0) { ///selection in menu depends on the value of int option lcd.drawCircle(70,4,2,1); } else if (option == 1) { lcd.drawCircle(55,20,2,1); @@ -623,23 +624,26 @@ lcd.drawCircle(35,35,2,1); } - if(g_button_flag) { + if(g_button_flag) { /// if button is pressed - g_button_flag = 0; + g_button_flag = 0; ///reset flag - if (option == 0) { + if (option == 0) { ///break the while loop, start game break; - } else if (option == 1) { - + } + + else if (option == 1) { ///enter settings menu + option = 0; while(1) { - updateJoystick(); + updateJoystick(); ///update joystick position lcd.clear(); - lcd.printString("Game speed",0,0); - lcd.printString("Lcd Mode",0,2); - lcd.printString("Sound",0,4); + lcd.printString("Game speed",0,0); ///print settings menu + lcd.printString("Lcd Mode",0,1); + lcd.printString("Sound",0,2); + lcd.printString("Back",0,3); switch (joystick.direction) { case UP: option--; @@ -651,24 +655,91 @@ option = option; break; } - if (option < 0) { - option = 2; + if (option < 0) { ///if selector is on the top of the screen and UP is pressed, selector goes to the bottom + option = 3; } - if (option > 2) { + if (option > 3) { ///if selector is on the bottom of the screen and DOWN is pressed, selector goes to the top option = 0; } if (option == 0) { - lcd.drawCircle(70,4,2,1); + lcd.drawCircle(70,4,2,1); /// menu selection depends on the position of the Joystick } else if (option == 1) { - lcd.drawCircle(55,20,2,1); + lcd.drawCircle(55,12,2,1); } else if (option == 2) { - lcd.drawCircle(35,35,2,1); + lcd.drawCircle(35,20,2,1); + } else { + lcd.drawCircle(35,27,2,1); + } + if (g_button_flag) { ///if button is pressed + g_button_flag = 0; ///reset button + + if (option == 0) { + + while(1) { ///set speed of the game + + updateJoystick(); + lcd.clear(); + lcd.printString("Slow",0,0); ///print game speed menu + lcd.printString("Normal",0,1); + lcd.printString("Fast",0,2); + lcd.printString("Back",0,3); + switch (joystick.direction) { + case UP: + option--; + break; + case DOWN: + option++; + break; + case CENTRE: + option = option; + break; + } + if (option < 0) { + option = 3; + } + if (option > 3) { + option = 0; + } + + if (option == 0) { + lcd.drawCircle(70,4,2,1); + } else if (option == 1) { + lcd.drawCircle(55,12,2,1); + } else if (option == 2) { + lcd.drawCircle(35,20,2,1); + } else { + lcd.drawCircle(35,27,2,1); + } + + if (g_button_flag) { + g_button_flag = 0; + + if (option == 0) { + game_speed = 0.1; + } else if (option == 1) { + game_speed = 0.05; + } else if (option == 2) { + game_speed = 0.04; + } else if (option == 3) { + break; + } + } + lcd.refresh(); + sleep(); sleep(); + } + } else if (option == 1) { /// Lcd inverse mode + lcd.inverseMode(); + } else if (option == 2) { ///select sound or not + buzzer.write(0.5); + } else if(option == 3) { ///go back to main menu + break; + } } lcd.refresh(); sleep(); } - } else if (option == 2) { + } else if (option == 2) { ///turn off LED lcd.clear(); lcd.turnOff(); deepsleep(); @@ -710,7 +781,7 @@ for (int j=35+heroY; j<48+heroY; j++) { int count = intersection(i,j); - //lcd.setPixel(i,j); + lcd.setPixel(i,j); } } }