My take on the classic Pac man game. Using mbed LPC 1768 and Nokia 5110 LCD Analog joystick used to control direction
Dependencies: N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 21:f2bcb2c399ab
- Parent:
- 20:874b009fea11
- Child:
- 22:03acb7389497
diff -r 874b009fea11 -r f2bcb2c399ab main.cpp --- a/main.cpp Wed Apr 29 18:48:43 2015 +0000 +++ b/main.cpp Wed Apr 29 19:25:24 2015 +0000 @@ -9,7 +9,7 @@ float frequency[]= {494,494,988,988,740,622,988,587,622,440,1047,784,659,1047,784,659,494,988,740,622,988,587,622,659,698,698,740,784,784,831,880,988}; //frequency array float beat[]= {0.5,0.5,0.5,0.5,0.5,1,1,0.5,0.5,0.5,0.5,0.5,1,1,0.5,0.5,0.5,0.5,0.5,1,1,0.25,0.5,0.25,0.25,0.5,0.25,0.25,0.5,1}; //beat array -int buttonflag2=0; + @@ -18,7 +18,7 @@ // Function Prototypes void pressWasted(); -void startscreen(); + void pause(); void winningcondition(); void losingcondition(); @@ -32,8 +32,8 @@ void Boundarycheck(); void WastedCheck(); void checkCoin(); -void pressStart() ; -void flagforbeat(); +void creditscreen(); + void tune() { @@ -48,23 +48,15 @@ } -void startscreen() +void creditscreen() { - lcd.printString("Welcome to",15,1); - lcd.printString("Pacman",20,2); - lcd.printString("Press Play",8,3); - - button.rise(&pressStart); + + lcd.printString("Thank You",15,1); + lcd.printString("For",14,2); + lcd.printString("Playing",8,3); - if(buttonflag2) { - tune(); - pause(); - } else { - startscreen(); - } - + } - void calibrateJoystick() // read default positions of the joystick to calibrate later readings { button.mode(PullDown); @@ -504,11 +496,7 @@ j--; } } -void pressStart() // ISR to swap direction of joystick -{ - buttonflag2=!buttonflag2; -} void WastedCheck() { button.rise(&pressWasted); // event generated on rising edge @@ -688,11 +676,16 @@ calibrateJoystick(); // get centred values of joystick pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 10 times per second PHY_PowerDown(); - + tune(); + + + while(win==false&& lose==false) { - startscreen(); - - lcd.setBrightness(bright); + + + + + lcd.setBrightness(bright); lcd.clear(); pause(); winningcondition(); @@ -716,13 +709,20 @@ lcd.clear(); lcd.printString("Yay!", 25,21); tune(); - + creditscreen(); } if (lose==true) { lcd.setBrightness(bright); lcd.clear(); lcd.printString("Game Over", 15,10); + tune(); + creditscreen(); } -} + + + + +} +