My ELEC2645 project. Nikollao Sulollari. 200804685
Dependencies: N5110 SoftPWM mbed
Diff: main.h
- Revision:
- 15:c7af2ea5f164
- Parent:
- 14:91ae0afe9037
- Child:
- 16:a6ca6858af24
--- a/main.h Fri Apr 29 14:19:57 2016 +0000 +++ b/main.h Fri Apr 29 19:35:13 2016 +0000 @@ -33,6 +33,31 @@ DigitalOut b_led(LED_BLUE); /** +@nameSpace blue_led +@brief output for status of blue LED +*/ +DigitalOut blue_led(PTA1); + +/** +@nameSpace left_led +@brief output for status of left LED +*/ +DigitalOut left_led(PTB23); + +/** +@nameSpace centre_led +@brief output for status of centre LED +*/ +DigitalOut centre_led(PTA2); + +/** +@nameSpace right_LED +@brief output for status of right LED +*/ +DigitalOut right_led(PTC2); + + +/** @nameSpace lcd @brief object of the N5110 class */ @@ -286,7 +311,7 @@ volatile int play = 0; /*!< counts the number of plays */ -volatile int tries = 0;/*!< counts the number of trials */ +volatile int tries = 3;/*!< counts the number of trials */ volatile int n;/*!< number of pixels overlapping */ @@ -306,8 +331,8 @@ int menuY = 5; -bool normal; - +bool normal=0; +bool sound = 0; void enemies() { /// generate enemies in the screen depending on the level difficulty @@ -372,11 +397,19 @@ } ///set x-axis boundaries so hero does not go out of screen - if (heroX > 35) { + if (heroX > 40) { + heroX = -40; + } + if (heroX < -45) { heroX = 35; } - if (heroX < -40) { - heroX = -40; + if (heroY < -45) { ///if hero has reached the top of the screen + heroY = 0; ///hero goes back to the bottom of the screen + level++; ///level increases by 1 + } + + if (heroY >= 0) {/// hero cannot go to previous level + heroY = 0; } ///draw hero lcd.drawLine(40+heroX, 47+heroY, 48+heroX, 43+heroY,1); @@ -391,12 +424,13 @@ circleY = circleY + rand() %4 - 2; if (circleY <= 10) { - circleY = 10; + circleY = 20; }if (circleY >= 35) { circleY = 35; } - - + if (circleX > 84) { + circleX = 0; + } circleX++; ///enemy moving towards hero } @@ -410,10 +444,10 @@ circleX = 0; lcd.setBrightness(0.5); // put LED backlight on 50% - timeout.attach(&timeout_isr,3); lcd.printString("Welcome to",11,1); lcd.printString("Treasure Hunt!",1,3); lcd.refresh(); + timeout.attach(&timeout_isr,3); sleep(); lcd.clear(); @@ -651,10 +685,31 @@ updateJoystick(); ///update joystick position lcd.clear(); - lcd.printString("Game speed",0,0); ///print settings menu - lcd.printString("Lcd: Normal",0,1); - lcd.printString("Sound: ON",0,2); - lcd.printString("Back",0,3); + if (normal) { + if (sound) { + lcd.printString("Game speed",0,0); ///print settings menu + lcd.printString("Lcd:Inverse",0,1); + lcd.printString("Sound:ON",0,2); + lcd.printString("Back",0,3); + } else { + lcd.printString("Game speed",0,0); ///print settings menu + lcd.printString("Lcd:Inverse",0,1); + lcd.printString("Sound:OFF",0,2); + lcd.printString("Back",0,3); + } + } else { + if (sound) { + lcd.printString("Game speed",0,0); ///print settings menu + lcd.printString("Lcd: Normal",0,1); + lcd.printString("Sound: ON",0,2); + lcd.printString("Back",0,3); + } else { + lcd.printString("Game speed",0,0); ///print settings menu + lcd.printString("Lcd: Normal",0,1); + lcd.printString("Sound: OFF",0,2); + lcd.printString("Back",0,3); + } + } switch (joystick.direction) { case UP: option--; @@ -677,9 +732,9 @@ if (option == 0) { lcd.drawCircle(70,4,2,1); } else if (option == 1) { - lcd.drawCircle(55,12,2,1); + lcd.drawCircle(70,12,2,1); } else if (option == 2) { - lcd.drawCircle(35,20,2,1); + lcd.drawCircle(70,20,2,1); } else { lcd.drawCircle(35,27,2,1); } @@ -689,13 +744,13 @@ if (option == 0) { /// if user selects to modify speed of the game 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--; @@ -743,13 +798,20 @@ } } else if (option == 1) { /// Lcd inverse mode normal =! normal; - if (normal){ - lcd.inverseMode(); - }else { - lcd.normalMode(); + if (normal) { + lcd.inverseMode(); + } else { + lcd.normalMode(); } } else if (option == 2) { ///select sound or not + + sound =! sound; + + if (sound) buzzer.write(0.5); + else + buzzer.write(0.0); + // buzzer.period(1/400); } else if(option == 3) { ///go back to main menu break; } @@ -797,26 +859,39 @@ for (int i=40+heroX; i<50+heroX; i++) { for (int j=35+heroY; j<48+heroY; j++) { - + int check = intersection(i,j); //lcd.setPixel(i,j); char bit[50]; sprintf(bit,"Pixels: %d",check); - - if (check > 7) { - for(int i = 40; i < 45; i++) { - for (int j = -20; i < 10; j++) { + - if (lcd.getPixel(i,j)!=0) { - check = 6; - } + for(int i = 40; i < 45; i++) { + for (int j = -5; i < 5; j++) { + + if (check > 6) { + check = 6; } } + } + if (check > 7) { lcd.printString(bit,0,0); lcd.refresh(); - wait(3); + tries--; + if(tries == 2) { + right_led = 0; + }else if (tries == 1) { + centre_led = 0; + }else if(tries == 0){ + left_led = 0; + //gameOver(); + } + wait(2); + heroX = 0; + heroY = 0; } + } } }