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:
- 5:61c3bbef19f0
- Parent:
- 4:75c7277a1b88
- Child:
- 6:af4d3c5a9d43
--- a/main.cpp Tue Apr 21 15:03:19 2015 +0000 +++ b/main.cpp Tue Apr 21 15:35:18 2015 +0000 @@ -11,7 +11,7 @@ AnalogIn xPot(p15);// Joystick x-direction AnalogIn yPot(p16);// Joystick y-direction int i=3; // Pacman's starting position -int j = 5; +int j = 3; Ticker pollJoystick; // timer to regularly read the joystick int next[84][48]= {0}; @@ -82,10 +82,10 @@ void drawMap() { + lcd.drawRect(41,20,10,2,1); lcd.drawRect(41,0,2,10,1); - } void checkRight() @@ -115,6 +115,29 @@ } } +void checkUp() +{ + int u=0; + if(lcd.getPixel (i,j-4))//Check 4 pixels above + u++; + if(lcd.getPixel (i,j-5))//Check 5 pixels above + u++; + if (u==2) { // Condition for solid obstacles + j++; +} +} + +void checkDown(){ + int d=0; + if(lcd.getPixel (i,j+4))//Check 4 pixels below + d++; + if(lcd.getPixel (i,j+5))//Check 5 pixels below + d++; + if (d==2) { // Condition for solid obstacles + j--; +} +} + void drawCoin() { if (coinflag) { @@ -143,10 +166,10 @@ if (i==30 &&j==3) { coinflag3=0; } - if (i==40 &&j==3) { + if (i==50 &&j==3) { coinflag4=0; } - if (i==50 &&j==3) { + if (i==60 &&j==3) { coinflag5=0; } @@ -201,6 +224,8 @@ drawCoin(); checkRight(); checkLeft(); + checkDown(); + checkUp(); Joystickcheck(); Boundarycheck(); checkCoin();