Code for 4180 mini project

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Fork of Pacman by Shawn Rigdon

Committer:
srigdon3
Date:
Tue Mar 25 18:49:05 2014 +0000
Revision:
1:b86030cf57c4
Parent:
0:0a900ff9a788
Child:
2:610d5194c64e
This program runs through one level of Pacman.  Be advised the game is not fully functional.  The ghost character was commented out due to the game freezing with multiple characters present.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
srigdon3 1:b86030cf57c4 1 /*
srigdon3 1:b86030cf57c4 2 So far, this program will run through one level of what will hopefully be a full Pacman game.
srigdon3 1:b86030cf57c4 3 As of now, only Pacman will run all the way through, so the thread to start the blue ghost has
srigdon3 1:b86030cf57c4 4 been commented out. This program only runs through one level of the game.
srigdon3 1:b86030cf57c4 5 */
srigdon3 1:b86030cf57c4 6
srigdon3 0:0a900ff9a788 7 #include "mbed.h"
srigdon3 0:0a900ff9a788 8 #include "rtos.h"
srigdon3 0:0a900ff9a788 9 #include "uLCD_4DGL.h"
srigdon3 0:0a900ff9a788 10
srigdon3 1:b86030cf57c4 11 #define PAC_SIZE 5 //The radius of Pacman and the ghost
srigdon3 1:b86030cf57c4 12 #define STEP_SIZE 8 //The number of pixels each character moves at once
srigdon3 1:b86030cf57c4 13 #define CLEARANCE 12 //The number of pixels each character checks ahead before moving
srigdon3 0:0a900ff9a788 14
srigdon3 0:0a900ff9a788 15 AnalogIn jsx(p19); // The joysticks origin is about 1.6V in both directions
srigdon3 1:b86030cf57c4 16 AnalogIn jsy(p20); // For just three states in each direction, thresholds .33V and 3V were used
srigdon3 0:0a900ff9a788 17 uLCD_4DGL uLCD(p28, p27, p29);
srigdon3 0:0a900ff9a788 18 Mutex lcd_mutex;
srigdon3 0:0a900ff9a788 19
srigdon3 1:b86030cf57c4 20 void checkMOVE(void); //This function is defined below. It was written here since other functions return to it that it also calls.
srigdon3 0:0a900ff9a788 21
srigdon3 1:b86030cf57c4 22 //several variables are used by multiple threads
srigdon3 1:b86030cf57c4 23 volatile bool win=false; //True when pacman has eaten all coins
srigdon3 1:b86030cf57c4 24 volatile bool lose=false; //True when the position of the ghost and pacman are the same
srigdon3 1:b86030cf57c4 25 volatile int x = 64; //x and y are pacman's position. The starting position is defined here.
srigdon3 0:0a900ff9a788 26 volatile int y = 88;
srigdon3 1:b86030cf57c4 27 volatile int gx1 = 64; //Starting position of the blue ghost
srigdon3 0:0a900ff9a788 28 volatile int gy1 = 40;
srigdon3 0:0a900ff9a788 29 int i;
srigdon3 0:0a900ff9a788 30 bool clearRIGHT,clearLEFT,clearUP,clearDOWN,bgcr,bgcl,bgcu,bgcd;
srigdon3 1:b86030cf57c4 31
srigdon3 1:b86030cf57c4 32 //An array containing the locations of the 81 coins pacman must eat
srigdon3 0:0a900ff9a788 33 int coins[81][2] = {
srigdon3 0:0a900ff9a788 34 {40,88},{48,88},{56,88},{72,88},{80,88},{88,88},
srigdon3 0:0a900ff9a788 35 {40,40},{48,40},{56,40},{64,40},{72,40},{80,40},{88,40},
srigdon3 0:0a900ff9a788 36 {40,48},{40,56},{40,64},{40,72},{40,80},
srigdon3 0:0a900ff9a788 37 {88,48},{88,56},{88,64},{88,72},{88,80},
srigdon3 0:0a900ff9a788 38 {56,96},{56,104},{56,112},
srigdon3 0:0a900ff9a788 39 {48,112},{40,112},{32,112},{24,112},{16,112},
srigdon3 0:0a900ff9a788 40 {16,104},{16,96},{16,88},{16,80},{16,72},
srigdon3 0:0a900ff9a788 41 {24,64},{32,64},
srigdon3 0:0a900ff9a788 42 {16,64},{16,56},{16,48},{16,40},{16,32},{16,24},{16,16},
srigdon3 0:0a900ff9a788 43 {24,16},{32,16},{40,16},{48,16},{56,16},
srigdon3 0:0a900ff9a788 44 {56,24},{56,32},
srigdon3 0:0a900ff9a788 45 {72,96},{72,104},{72,112},
srigdon3 0:0a900ff9a788 46 {80,112},{88,112},{96,112},{104,112},{112,112},
srigdon3 0:0a900ff9a788 47 {112,104},{112,96},{112,88},{112,80},{112,72},
srigdon3 0:0a900ff9a788 48 {104,64},{96,64},
srigdon3 0:0a900ff9a788 49 {112,64},{112,56},{112,48},{112,40},{112,32},{112,24},{112,16},
srigdon3 0:0a900ff9a788 50 {104,16},{96,16},{88,16},{80,16},{72,16},
srigdon3 0:0a900ff9a788 51 {72,24},{72,32}
srigdon3 0:0a900ff9a788 52 };
srigdon3 0:0a900ff9a788 53
srigdon3 1:b86030cf57c4 54 //This function is used in the ghost thread to replace coins as it passes over them
srigdon3 0:0a900ff9a788 55 void replaceCOINS(void)
srigdon3 0:0a900ff9a788 56 {
srigdon3 0:0a900ff9a788 57 for(int n=0; n<81; n++)
srigdon3 0:0a900ff9a788 58 {
srigdon3 1:b86030cf57c4 59 lcd_mutex.lock(); //The coins array is used by both threads
srigdon3 0:0a900ff9a788 60 if(gx1 == coins[n][0] && gy1 == coins[n][1])
srigdon3 0:0a900ff9a788 61 {
srigdon3 1:b86030cf57c4 62 uLCD.filled_circle(gx1,gy1,1,0xFFFF00); //compare the set of coins to the ghost's previous position and if there is a match redraw coin
srigdon3 0:0a900ff9a788 63 }
srigdon3 0:0a900ff9a788 64 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 65 }
srigdon3 0:0a900ff9a788 66 }
srigdon3 0:0a900ff9a788 67
srigdon3 1:b86030cf57c4 68 //Checks if the ghost can move right (there is no boundary immediately to the right)
srigdon3 0:0a900ff9a788 69 void BGclearRIGHT(void)
srigdon3 0:0a900ff9a788 70 {
srigdon3 0:0a900ff9a788 71 bgcr = true;
srigdon3 0:0a900ff9a788 72 for(int p=gx1; p <= gx1+CLEARANCE; p++)
srigdon3 0:0a900ff9a788 73 {
srigdon3 0:0a900ff9a788 74 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 75 if(uLCD.read_pixel(p,gy1)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 76 {
srigdon3 1:b86030cf57c4 77 bgcr = false; //compare the pixels immediately in front of the ghost to the boundary up to the spec. clearance
srigdon3 1:b86030cf57c4 78 } //if they are the same color, determine the ghost can't move right
srigdon3 0:0a900ff9a788 79 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 80 }
srigdon3 0:0a900ff9a788 81 }
srigdon3 0:0a900ff9a788 82
srigdon3 1:b86030cf57c4 83 //Checks if ghost can move left
srigdon3 0:0a900ff9a788 84 void BGclearLEFT(void)
srigdon3 0:0a900ff9a788 85 {
srigdon3 0:0a900ff9a788 86 bgcl = true;
srigdon3 0:0a900ff9a788 87 for(int p=gx1; p >= gx1-CLEARANCE; p--)
srigdon3 0:0a900ff9a788 88 {
srigdon3 0:0a900ff9a788 89 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 90 if(uLCD.read_pixel(p,gy1)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 91 {
srigdon3 0:0a900ff9a788 92 bgcl = false;
srigdon3 0:0a900ff9a788 93 }
srigdon3 0:0a900ff9a788 94 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 95 }
srigdon3 0:0a900ff9a788 96 }
srigdon3 0:0a900ff9a788 97
srigdon3 1:b86030cf57c4 98 //Checks if ghost can move up
srigdon3 0:0a900ff9a788 99 void BGclearUP(void)
srigdon3 0:0a900ff9a788 100 {
srigdon3 0:0a900ff9a788 101 bgcu = true;
srigdon3 0:0a900ff9a788 102 for(int p=gy1; p >= gy1-CLEARANCE; p--)
srigdon3 0:0a900ff9a788 103 {
srigdon3 0:0a900ff9a788 104 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 105 if(uLCD.read_pixel(gx1,p)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 106 {
srigdon3 0:0a900ff9a788 107 bgcu = false;
srigdon3 0:0a900ff9a788 108 }
srigdon3 0:0a900ff9a788 109 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 110 }
srigdon3 0:0a900ff9a788 111 }
srigdon3 0:0a900ff9a788 112
srigdon3 1:b86030cf57c4 113 //Checks if ghost can move down
srigdon3 0:0a900ff9a788 114 void BGclearDOWN(void)
srigdon3 0:0a900ff9a788 115 {
srigdon3 0:0a900ff9a788 116 bgcd = true;
srigdon3 0:0a900ff9a788 117 for(int p=gy1; p <= gy1+CLEARANCE; p++)
srigdon3 0:0a900ff9a788 118 {
srigdon3 0:0a900ff9a788 119 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 120 if(uLCD.read_pixel(gx1,p)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 121 {
srigdon3 0:0a900ff9a788 122 bgcd = false;
srigdon3 0:0a900ff9a788 123 }
srigdon3 0:0a900ff9a788 124 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 125 }
srigdon3 0:0a900ff9a788 126 }
srigdon3 0:0a900ff9a788 127
srigdon3 1:b86030cf57c4 128 //Moves the blue ghost to the right
srigdon3 0:0a900ff9a788 129 void bgRIGHT(void)
srigdon3 0:0a900ff9a788 130 {
srigdon3 0:0a900ff9a788 131 Thread::wait(50);
srigdon3 0:0a900ff9a788 132 lcd_mutex.lock();
srigdon3 1:b86030cf57c4 133 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1-PAC_SIZE,gx1+PAC_SIZE,gy1+PAC_SIZE,BLACK); //erase the previous ghost drawing
srigdon3 0:0a900ff9a788 134 lcd_mutex.unlock();
srigdon3 1:b86030cf57c4 135 replaceCOINS(); //replace the coin the ghost was just on if there was one
srigdon3 1:b86030cf57c4 136 if(gx1>124) //This will cause the ghost to wrap around to the left side of the screen if there were no boundary on the far right
srigdon3 0:0a900ff9a788 137 {
srigdon3 0:0a900ff9a788 138 gx1 = 0;
srigdon3 0:0a900ff9a788 139 }
srigdon3 1:b86030cf57c4 140 gx1 = gx1+STEP_SIZE; //Move one step size in the x direction
srigdon3 0:0a900ff9a788 141 lcd_mutex.lock();
srigdon3 1:b86030cf57c4 142 //redraw the ghost at the new position
srigdon3 0:0a900ff9a788 143 uLCD.filled_circle(gx1,gy1,PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 144 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1,gx1+PAC_SIZE,gy1+PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 145 uLCD.filled_circle(gx1+2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 146 uLCD.filled_circle(gx1-2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 147 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 148 }
srigdon3 0:0a900ff9a788 149
srigdon3 1:b86030cf57c4 150 //Moves the blue ghost left
srigdon3 0:0a900ff9a788 151 void bgLEFT(void)
srigdon3 0:0a900ff9a788 152 {
srigdon3 0:0a900ff9a788 153 Thread::wait(50);
srigdon3 0:0a900ff9a788 154 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 155 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1-PAC_SIZE,gx1+PAC_SIZE,gy1+PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 156 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 157 replaceCOINS();
srigdon3 0:0a900ff9a788 158 if(gx1<4)
srigdon3 0:0a900ff9a788 159 {
srigdon3 0:0a900ff9a788 160 gx1 = 124;
srigdon3 0:0a900ff9a788 161 }
srigdon3 0:0a900ff9a788 162 gx1 = gx1-STEP_SIZE;
srigdon3 0:0a900ff9a788 163 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 164 uLCD.filled_circle(gx1,gy1,PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 165 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1,gx1+PAC_SIZE,gy1+PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 166 uLCD.filled_circle(gx1+2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 167 uLCD.filled_circle(gx1-2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 168 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 169 }
srigdon3 0:0a900ff9a788 170
srigdon3 1:b86030cf57c4 171 //Moves the blue ghost up
srigdon3 0:0a900ff9a788 172 void bgUP(void)
srigdon3 0:0a900ff9a788 173 {
srigdon3 0:0a900ff9a788 174 Thread::wait(50);
srigdon3 0:0a900ff9a788 175 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 176 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1-PAC_SIZE,gx1+PAC_SIZE,gy1+PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 177 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 178 replaceCOINS();
srigdon3 0:0a900ff9a788 179 if(gy1<4)
srigdon3 0:0a900ff9a788 180 {
srigdon3 0:0a900ff9a788 181 gy1 = 124;
srigdon3 0:0a900ff9a788 182 }
srigdon3 0:0a900ff9a788 183 gy1 = gy1-STEP_SIZE;
srigdon3 0:0a900ff9a788 184 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 185 uLCD.filled_circle(gx1,gy1,PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 186 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1,gx1+PAC_SIZE,gy1+PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 187 uLCD.filled_circle(gx1+2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 188 uLCD.filled_circle(gx1-2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 189 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 190 }
srigdon3 0:0a900ff9a788 191
srigdon3 1:b86030cf57c4 192 //Moves the blue ghost down
srigdon3 0:0a900ff9a788 193 void bgDOWN(void)
srigdon3 0:0a900ff9a788 194 {
srigdon3 0:0a900ff9a788 195 Thread::wait(50);
srigdon3 0:0a900ff9a788 196 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 197 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1-PAC_SIZE,gx1+PAC_SIZE,gy1+PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 198 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 199 replaceCOINS();
srigdon3 0:0a900ff9a788 200 if(gy1>124)
srigdon3 0:0a900ff9a788 201 {
srigdon3 0:0a900ff9a788 202 gy1 = 0;
srigdon3 0:0a900ff9a788 203 }
srigdon3 0:0a900ff9a788 204 gy1 = gy1+STEP_SIZE;
srigdon3 0:0a900ff9a788 205 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 206 uLCD.filled_circle(gx1,gy1,PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 207 uLCD.filled_rectangle(gx1-PAC_SIZE,gy1,gx1+PAC_SIZE,gy1+PAC_SIZE,BLUE);
srigdon3 0:0a900ff9a788 208 uLCD.filled_circle(gx1+2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 209 uLCD.filled_circle(gx1-2,gy1-2,1,BLACK);
srigdon3 0:0a900ff9a788 210 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 211 }
srigdon3 0:0a900ff9a788 212
srigdon3 1:b86030cf57c4 213 //Force ghost to chase Pacman
srigdon3 0:0a900ff9a788 214 void follow(void)
srigdon3 0:0a900ff9a788 215 {
srigdon3 1:b86030cf57c4 216 if(x==gx1 && y==gy1) //if the ghost and Pacman are at the same position trigger losing condition
srigdon3 0:0a900ff9a788 217 {
srigdon3 1:b86030cf57c4 218 win = true; //This is set to true just to exit the check for a win loop and terminate other loops without writing additional conditions
srigdon3 0:0a900ff9a788 219 lose = true;
srigdon3 0:0a900ff9a788 220 }
srigdon3 1:b86030cf57c4 221 while(x==gx1 && gy1<y && !win) //If the ghost is directly above Pacman check to see if moving down is possible, then move down
srigdon3 0:0a900ff9a788 222 {
srigdon3 1:b86030cf57c4 223 BGclearDOWN();
srigdon3 0:0a900ff9a788 224 bgDOWN();
srigdon3 0:0a900ff9a788 225 }
srigdon3 0:0a900ff9a788 226 while(x==gx1 && gy1>y && !win)
srigdon3 0:0a900ff9a788 227 {
srigdon3 0:0a900ff9a788 228 BGclearUP();
srigdon3 0:0a900ff9a788 229 bgUP();
srigdon3 0:0a900ff9a788 230 }
srigdon3 0:0a900ff9a788 231 while(y==gy1 && gx1<x && !win)
srigdon3 0:0a900ff9a788 232 {
srigdon3 0:0a900ff9a788 233 BGclearRIGHT();
srigdon3 0:0a900ff9a788 234 bgRIGHT();
srigdon3 0:0a900ff9a788 235 }
srigdon3 0:0a900ff9a788 236 while(y==gy1 && gx1>x && !win)
srigdon3 0:0a900ff9a788 237 {
srigdon3 0:0a900ff9a788 238 BGclearLEFT();
srigdon3 0:0a900ff9a788 239 bgLEFT();
srigdon3 0:0a900ff9a788 240 }
srigdon3 0:0a900ff9a788 241 }
srigdon3 0:0a900ff9a788 242
srigdon3 1:b86030cf57c4 243 //Ghost selects a direction to move
srigdon3 0:0a900ff9a788 244 void pickMOVE(void)
srigdon3 0:0a900ff9a788 245 {
srigdon3 1:b86030cf57c4 246 while((gx1==x || gy1==y) && abs(x-gx1)+abs(y-gy1)<=16 && !win) //If Pacman is close by give chase
srigdon3 0:0a900ff9a788 247 {
srigdon3 0:0a900ff9a788 248 follow();
srigdon3 0:0a900ff9a788 249 }
srigdon3 1:b86030cf57c4 250 int dec = rand()%4; //randomly generate a number from the set 0,1,2,3, which serves as the direction decision
srigdon3 0:0a900ff9a788 251 if(dec == 0)
srigdon3 0:0a900ff9a788 252 {
srigdon3 0:0a900ff9a788 253 BGclearRIGHT();
srigdon3 1:b86030cf57c4 254 while(bgcr && !win) //If decision 0 was reached, check to the the move right until a boundary is reached
srigdon3 0:0a900ff9a788 255 {
srigdon3 0:0a900ff9a788 256 bgRIGHT();
srigdon3 0:0a900ff9a788 257 BGclearRIGHT();
srigdon3 0:0a900ff9a788 258 }
srigdon3 0:0a900ff9a788 259 }
srigdon3 0:0a900ff9a788 260 else if(dec == 1)
srigdon3 0:0a900ff9a788 261 {
srigdon3 0:0a900ff9a788 262 BGclearLEFT();
srigdon3 0:0a900ff9a788 263 while(bgcl && !win)
srigdon3 0:0a900ff9a788 264 {
srigdon3 0:0a900ff9a788 265 bgLEFT();
srigdon3 0:0a900ff9a788 266 BGclearLEFT();
srigdon3 0:0a900ff9a788 267 }
srigdon3 0:0a900ff9a788 268 }
srigdon3 0:0a900ff9a788 269 else if(dec == 2)
srigdon3 0:0a900ff9a788 270 {
srigdon3 0:0a900ff9a788 271 BGclearUP();
srigdon3 0:0a900ff9a788 272 while(bgcu && !win)
srigdon3 0:0a900ff9a788 273 {
srigdon3 0:0a900ff9a788 274 bgUP();
srigdon3 0:0a900ff9a788 275 BGclearUP();
srigdon3 0:0a900ff9a788 276 }
srigdon3 0:0a900ff9a788 277 }
srigdon3 0:0a900ff9a788 278 else
srigdon3 0:0a900ff9a788 279 {
srigdon3 0:0a900ff9a788 280 BGclearDOWN();
srigdon3 0:0a900ff9a788 281 while(bgcd && !win)
srigdon3 0:0a900ff9a788 282 {
srigdon3 0:0a900ff9a788 283 bgDOWN();
srigdon3 0:0a900ff9a788 284 BGclearDOWN();
srigdon3 0:0a900ff9a788 285 }
srigdon3 0:0a900ff9a788 286 }
srigdon3 0:0a900ff9a788 287 }
srigdon3 0:0a900ff9a788 288
srigdon3 1:b86030cf57c4 289 //Check if Pacman can move one step size to the right (Essentially the same as checking for the ghost)
srigdon3 0:0a900ff9a788 290 void CHECKclearRIGHT(void)
srigdon3 0:0a900ff9a788 291 {
srigdon3 0:0a900ff9a788 292 clearRIGHT = true;
srigdon3 0:0a900ff9a788 293 for(i=x; i <= x+CLEARANCE; i++)
srigdon3 0:0a900ff9a788 294 {
srigdon3 0:0a900ff9a788 295 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 296 if(uLCD.read_pixel(i,y)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 297 {
srigdon3 0:0a900ff9a788 298 clearRIGHT = false;
srigdon3 0:0a900ff9a788 299 }
srigdon3 0:0a900ff9a788 300 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 301 }
srigdon3 0:0a900ff9a788 302 }
srigdon3 0:0a900ff9a788 303
srigdon3 1:b86030cf57c4 304 //Check if Pacman can move left
srigdon3 0:0a900ff9a788 305 void CHECKclearLEFT(void)
srigdon3 0:0a900ff9a788 306 {
srigdon3 0:0a900ff9a788 307 clearLEFT = true;
srigdon3 0:0a900ff9a788 308 for(i=x; i >= x-CLEARANCE; i--)
srigdon3 0:0a900ff9a788 309 {
srigdon3 0:0a900ff9a788 310 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 311 if(uLCD.read_pixel(i,y)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 312 {
srigdon3 0:0a900ff9a788 313 clearLEFT = false;
srigdon3 0:0a900ff9a788 314 }
srigdon3 0:0a900ff9a788 315 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 316 }
srigdon3 0:0a900ff9a788 317 }
srigdon3 0:0a900ff9a788 318
srigdon3 1:b86030cf57c4 319 //Check if Pacman can move up
srigdon3 0:0a900ff9a788 320 void CHECKclearUP(void)
srigdon3 0:0a900ff9a788 321 {
srigdon3 0:0a900ff9a788 322 clearUP = true;
srigdon3 0:0a900ff9a788 323 for(i=y; i >= y-CLEARANCE; i--)
srigdon3 0:0a900ff9a788 324 {
srigdon3 0:0a900ff9a788 325 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 326 if(uLCD.read_pixel(x,i)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 327 {
srigdon3 0:0a900ff9a788 328 clearUP = false;
srigdon3 0:0a900ff9a788 329 }
srigdon3 0:0a900ff9a788 330 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 331 }
srigdon3 0:0a900ff9a788 332 }
srigdon3 0:0a900ff9a788 333
srigdon3 1:b86030cf57c4 334 //Check if Pacman can move down
srigdon3 0:0a900ff9a788 335 void CHECKclearDOWN(void)
srigdon3 0:0a900ff9a788 336 {
srigdon3 0:0a900ff9a788 337 clearDOWN = true;
srigdon3 0:0a900ff9a788 338 for(i=y; i <= y+CLEARANCE; i++)
srigdon3 0:0a900ff9a788 339 {
srigdon3 0:0a900ff9a788 340 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 341 if(uLCD.read_pixel(x,i)==uLCD.read_pixel(4,4))
srigdon3 0:0a900ff9a788 342 {
srigdon3 0:0a900ff9a788 343 clearDOWN = false;
srigdon3 0:0a900ff9a788 344 }
srigdon3 0:0a900ff9a788 345 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 346 }
srigdon3 0:0a900ff9a788 347 }
srigdon3 0:0a900ff9a788 348
srigdon3 1:b86030cf57c4 349 //This function tracks the coin Pacman eats as he passes over it
srigdon3 0:0a900ff9a788 350 void changeCOINS(void)
srigdon3 0:0a900ff9a788 351 {
srigdon3 0:0a900ff9a788 352 for(int m=0; m<81; m++)
srigdon3 0:0a900ff9a788 353 {
srigdon3 0:0a900ff9a788 354 lcd_mutex.lock();
srigdon3 1:b86030cf57c4 355 if(x == coins[m][0] && y == coins[m][1]) //Compare Pacman's position to the set of coins
srigdon3 0:0a900ff9a788 356 {
srigdon3 1:b86030cf57c4 357 coins[m][0]=64; //If there is a match, change that coins location to the center of the board where Pacman
srigdon3 1:b86030cf57c4 358 coins[m][1]=64; //cannot go, but do not draw the coin
srigdon3 0:0a900ff9a788 359 }
srigdon3 0:0a900ff9a788 360 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 361 }
srigdon3 0:0a900ff9a788 362 }
srigdon3 0:0a900ff9a788 363
srigdon3 1:b86030cf57c4 364 //Move Pacman one step size to the right
srigdon3 0:0a900ff9a788 365 void PACmoveRIGHT(void)
srigdon3 0:0a900ff9a788 366 {
srigdon3 1:b86030cf57c4 367 while(clearRIGHT && !win) //Not win indicates the game has not ended
srigdon3 0:0a900ff9a788 368 {
srigdon3 0:0a900ff9a788 369 lcd_mutex.lock();
srigdon3 1:b86030cf57c4 370 uLCD.filled_circle(x,y,PAC_SIZE,BLACK); //Erase Pacman at his last location
srigdon3 0:0a900ff9a788 371 lcd_mutex.unlock();
srigdon3 1:b86030cf57c4 372 if(x>124) //wrap around if moving off the board
srigdon3 0:0a900ff9a788 373 {
srigdon3 0:0a900ff9a788 374 x = 0;
srigdon3 0:0a900ff9a788 375 }
srigdon3 1:b86030cf57c4 376 x = x+STEP_SIZE; //move Pacman one step size to the right
srigdon3 1:b86030cf57c4 377 changeCOINS(); //Track the coin that was eaten at the last location
srigdon3 0:0a900ff9a788 378
srigdon3 1:b86030cf57c4 379 if(x%(2*STEP_SIZE) == 0) //There are two drawings provided for Pacman. The if statement causes Pacman to open his mouth every other move.
srigdon3 0:0a900ff9a788 380 {
srigdon3 0:0a900ff9a788 381 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 382 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 383 uLCD.filled_rectangle(x+2,y-2,x+PAC_SIZE,y+2,BLACK);
srigdon3 0:0a900ff9a788 384 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 385 }
srigdon3 0:0a900ff9a788 386 else
srigdon3 0:0a900ff9a788 387 {
srigdon3 0:0a900ff9a788 388 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 389 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 390 uLCD.filled_rectangle(x+2,y,x+PAC_SIZE,y+1,BLACK);
srigdon3 0:0a900ff9a788 391 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 392 }
srigdon3 1:b86030cf57c4 393 if(jsx <= .9) //If the user is still holding the joystick to the right, remain in this loop
srigdon3 0:0a900ff9a788 394 {
srigdon3 0:0a900ff9a788 395 checkMOVE();
srigdon3 0:0a900ff9a788 396 }
srigdon3 1:b86030cf57c4 397 CHECKclearRIGHT(); //If the user remains in the loop, check for a boundary to the right
srigdon3 0:0a900ff9a788 398 Thread::wait(10);
srigdon3 0:0a900ff9a788 399 }
srigdon3 0:0a900ff9a788 400 }
srigdon3 0:0a900ff9a788 401
srigdon3 1:b86030cf57c4 402 //Move Pacman left
srigdon3 0:0a900ff9a788 403 void PACmoveLEFT(void)
srigdon3 0:0a900ff9a788 404 {
srigdon3 0:0a900ff9a788 405 while(clearLEFT && !win)
srigdon3 0:0a900ff9a788 406 {
srigdon3 0:0a900ff9a788 407 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 408 uLCD.filled_circle(x,y,PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 409 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 410 if(x<4)
srigdon3 0:0a900ff9a788 411 {
srigdon3 0:0a900ff9a788 412 x = 128;
srigdon3 0:0a900ff9a788 413 }
srigdon3 0:0a900ff9a788 414 x = x-STEP_SIZE;
srigdon3 0:0a900ff9a788 415 changeCOINS();
srigdon3 0:0a900ff9a788 416 if(x%(2*STEP_SIZE) == 0)
srigdon3 0:0a900ff9a788 417 {
srigdon3 0:0a900ff9a788 418 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 419 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 420 uLCD.filled_rectangle(x-2,y-2,x-PAC_SIZE,y+2,BLACK);
srigdon3 0:0a900ff9a788 421 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 422 }
srigdon3 0:0a900ff9a788 423 else
srigdon3 0:0a900ff9a788 424 {
srigdon3 0:0a900ff9a788 425 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 426 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 427 uLCD.filled_rectangle(x-2,y,x-PAC_SIZE,y+1,BLACK);
srigdon3 0:0a900ff9a788 428 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 429 }
srigdon3 0:0a900ff9a788 430 if(jsx >= .1)
srigdon3 0:0a900ff9a788 431 {
srigdon3 0:0a900ff9a788 432 checkMOVE();
srigdon3 0:0a900ff9a788 433 }
srigdon3 0:0a900ff9a788 434 CHECKclearLEFT();
srigdon3 0:0a900ff9a788 435 Thread::wait(10);
srigdon3 0:0a900ff9a788 436 }
srigdon3 0:0a900ff9a788 437 }
srigdon3 0:0a900ff9a788 438
srigdon3 1:b86030cf57c4 439 //Move Pacman up
srigdon3 0:0a900ff9a788 440 void PACmoveUP(void)
srigdon3 0:0a900ff9a788 441 {
srigdon3 0:0a900ff9a788 442 while(clearUP && !win)
srigdon3 0:0a900ff9a788 443 {
srigdon3 0:0a900ff9a788 444 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 445 uLCD.filled_circle(x,y,PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 446 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 447 if(y<4)
srigdon3 0:0a900ff9a788 448 {
srigdon3 0:0a900ff9a788 449 y = 128;
srigdon3 0:0a900ff9a788 450 }
srigdon3 0:0a900ff9a788 451 y = y-STEP_SIZE;
srigdon3 0:0a900ff9a788 452 changeCOINS();
srigdon3 0:0a900ff9a788 453 if(y%(2*STEP_SIZE) == 0)
srigdon3 0:0a900ff9a788 454 {
srigdon3 0:0a900ff9a788 455 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 456 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 457 uLCD.filled_rectangle(x-2,y-2,x+2,y-PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 458 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 459 }
srigdon3 0:0a900ff9a788 460 else
srigdon3 0:0a900ff9a788 461 {
srigdon3 0:0a900ff9a788 462 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 463 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 464 uLCD.filled_rectangle(x,y-2,x+1,y-PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 465 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 466 }
srigdon3 0:0a900ff9a788 467 if(jsy <= .9)
srigdon3 0:0a900ff9a788 468 {
srigdon3 0:0a900ff9a788 469 checkMOVE();
srigdon3 0:0a900ff9a788 470 }
srigdon3 0:0a900ff9a788 471 CHECKclearUP();
srigdon3 0:0a900ff9a788 472 Thread::wait(10);
srigdon3 0:0a900ff9a788 473 }
srigdon3 0:0a900ff9a788 474 }
srigdon3 0:0a900ff9a788 475
srigdon3 1:b86030cf57c4 476 //Move Pacman down
srigdon3 0:0a900ff9a788 477 void PACmoveDOWN(void)
srigdon3 0:0a900ff9a788 478 {
srigdon3 0:0a900ff9a788 479 while(clearDOWN && !win)
srigdon3 0:0a900ff9a788 480 {
srigdon3 0:0a900ff9a788 481 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 482 uLCD.filled_circle(x,y,PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 483 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 484 if(y>124)
srigdon3 0:0a900ff9a788 485 {
srigdon3 0:0a900ff9a788 486 y = 0;
srigdon3 0:0a900ff9a788 487 }
srigdon3 0:0a900ff9a788 488 y = y+STEP_SIZE;
srigdon3 0:0a900ff9a788 489 changeCOINS();
srigdon3 0:0a900ff9a788 490 if(y%(2*STEP_SIZE) == 0)
srigdon3 0:0a900ff9a788 491 {
srigdon3 0:0a900ff9a788 492 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 493 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 494 uLCD.filled_rectangle(x-2,y+2,x+2,y+PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 495 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 496 }
srigdon3 0:0a900ff9a788 497 else
srigdon3 0:0a900ff9a788 498 {
srigdon3 0:0a900ff9a788 499 lcd_mutex.lock();
srigdon3 0:0a900ff9a788 500 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 501 uLCD.filled_rectangle(x,y+2,x+1,y+PAC_SIZE,BLACK);
srigdon3 0:0a900ff9a788 502 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 503 }
srigdon3 0:0a900ff9a788 504 if(jsy >= .1)
srigdon3 0:0a900ff9a788 505 {
srigdon3 0:0a900ff9a788 506 checkMOVE();
srigdon3 0:0a900ff9a788 507 }
srigdon3 0:0a900ff9a788 508 CHECKclearDOWN();
srigdon3 0:0a900ff9a788 509 Thread::wait(10);
srigdon3 0:0a900ff9a788 510 }
srigdon3 0:0a900ff9a788 511 }
srigdon3 0:0a900ff9a788 512
srigdon3 1:b86030cf57c4 513 //Read the input from the joystick and select a direction to move
srigdon3 1:b86030cf57c4 514 //The thresholds are set near the end of their ranges to eliminate unintentional moves as much as possible
srigdon3 0:0a900ff9a788 515 void checkMOVE(void)
srigdon3 0:0a900ff9a788 516 {
srigdon3 0:0a900ff9a788 517 if(jsx > .9)
srigdon3 0:0a900ff9a788 518 {
srigdon3 0:0a900ff9a788 519 CHECKclearRIGHT();
srigdon3 0:0a900ff9a788 520 PACmoveRIGHT();
srigdon3 0:0a900ff9a788 521 }
srigdon3 0:0a900ff9a788 522 else if(jsx < .1)
srigdon3 0:0a900ff9a788 523 {
srigdon3 0:0a900ff9a788 524 CHECKclearLEFT();
srigdon3 0:0a900ff9a788 525 PACmoveLEFT();
srigdon3 0:0a900ff9a788 526 }
srigdon3 0:0a900ff9a788 527 if(jsy > .9)
srigdon3 0:0a900ff9a788 528 {
srigdon3 0:0a900ff9a788 529 CHECKclearUP();
srigdon3 0:0a900ff9a788 530 PACmoveUP();
srigdon3 0:0a900ff9a788 531 }
srigdon3 0:0a900ff9a788 532 else if(jsy < .1)
srigdon3 0:0a900ff9a788 533 {
srigdon3 0:0a900ff9a788 534 CHECKclearDOWN();
srigdon3 0:0a900ff9a788 535 PACmoveDOWN();
srigdon3 0:0a900ff9a788 536 }
srigdon3 0:0a900ff9a788 537 }
srigdon3 0:0a900ff9a788 538
srigdon3 1:b86030cf57c4 539 //Draw the boudaries for the game using the uLCD graphics commands
srigdon3 0:0a900ff9a788 540 void drawBORDERS(void)
srigdon3 0:0a900ff9a788 541 {
srigdon3 0:0a900ff9a788 542 //Outer Border
srigdon3 0:0a900ff9a788 543 uLCD.rectangle(4,4,124,124,RED);
srigdon3 0:0a900ff9a788 544 uLCD.line(8,8,8,120,RED);
srigdon3 0:0a900ff9a788 545 uLCD.line(8,8,62,8,RED);
srigdon3 0:0a900ff9a788 546 uLCD.line(62,8,62,32,RED);
srigdon3 0:0a900ff9a788 547 uLCD.line(62,32,66,32,RED);
srigdon3 0:0a900ff9a788 548 uLCD.line(66,32,66,8,RED);
srigdon3 0:0a900ff9a788 549 uLCD.line(66,8,120,8,RED);
srigdon3 0:0a900ff9a788 550 uLCD.line(120,8,120,120,RED);
srigdon3 0:0a900ff9a788 551 uLCD.line(120,120,66,120,RED);
srigdon3 0:0a900ff9a788 552 uLCD.line(66,120,66,96,RED);
srigdon3 0:0a900ff9a788 553 uLCD.line(66,96,62,96,RED);
srigdon3 0:0a900ff9a788 554 uLCD.line(62,96,62,120,RED);
srigdon3 0:0a900ff9a788 555 uLCD.line(62,120,8,120,RED);
srigdon3 0:0a900ff9a788 556 //Inner Rectangle
srigdon3 0:0a900ff9a788 557 uLCD.rectangle(52,52,76,76,RED);
srigdon3 0:0a900ff9a788 558 uLCD.rectangle(48,48,80,80,RED);
srigdon3 0:0a900ff9a788 559 //Upper Left Corner
srigdon3 0:0a900ff9a788 560 uLCD.line(48,24,24,24,RED);
srigdon3 0:0a900ff9a788 561 uLCD.line(24,24,24,56,RED);
srigdon3 0:0a900ff9a788 562 uLCD.line(24,56,32,56,RED);
srigdon3 0:0a900ff9a788 563 uLCD.line(32,56,32,32,RED);
srigdon3 0:0a900ff9a788 564 uLCD.line(32,32,48,32,RED);
srigdon3 0:0a900ff9a788 565 uLCD.line(48,32,48,24,RED);
srigdon3 0:0a900ff9a788 566 //Upper Right Corner
srigdon3 0:0a900ff9a788 567 uLCD.line(80,24,104,24,RED);
srigdon3 0:0a900ff9a788 568 uLCD.line(104,24,104,56,RED);
srigdon3 0:0a900ff9a788 569 uLCD.line(104,56,96,56,RED);
srigdon3 0:0a900ff9a788 570 uLCD.line(96,56,96,32,RED);
srigdon3 0:0a900ff9a788 571 uLCD.line(96,32,80,32,RED);
srigdon3 0:0a900ff9a788 572 uLCD.line(80,32,80,24,RED);
srigdon3 0:0a900ff9a788 573 //Lower Left Corner
srigdon3 0:0a900ff9a788 574 uLCD.line(48,104,24,104,RED);
srigdon3 0:0a900ff9a788 575 uLCD.line(24,104,24,72,RED);
srigdon3 0:0a900ff9a788 576 uLCD.line(24,72,32,72,RED);
srigdon3 0:0a900ff9a788 577 uLCD.line(32,72,32,96,RED);
srigdon3 0:0a900ff9a788 578 uLCD.line(32,96,48,96,RED);
srigdon3 0:0a900ff9a788 579 uLCD.line(48,96,48,104,RED);
srigdon3 0:0a900ff9a788 580 //Lower Right Corner
srigdon3 0:0a900ff9a788 581 uLCD.line(80,104,104,104,RED);
srigdon3 0:0a900ff9a788 582 uLCD.line(104,104,104,72,RED);
srigdon3 0:0a900ff9a788 583 uLCD.line(104,72,96,72,RED);
srigdon3 0:0a900ff9a788 584 uLCD.line(96,72,96,96,RED);
srigdon3 0:0a900ff9a788 585 uLCD.line(96,96,80,96,RED);
srigdon3 0:0a900ff9a788 586 uLCD.line(80,96,80,104,RED);
srigdon3 0:0a900ff9a788 587 }
srigdon3 0:0a900ff9a788 588
srigdon3 0:0a900ff9a788 589 void placeCOINS(void)
srigdon3 0:0a900ff9a788 590 {
srigdon3 0:0a900ff9a788 591 for(int j=0; j<81; j++)
srigdon3 0:0a900ff9a788 592 {
srigdon3 1:b86030cf57c4 593 uLCD.filled_circle(coins[j][0],coins[j][1],1,0xFFFF00); //Draw the coins in their initial locations
srigdon3 0:0a900ff9a788 594 }
srigdon3 0:0a900ff9a788 595 }
srigdon3 0:0a900ff9a788 596
srigdon3 1:b86030cf57c4 597 //Draw all the initial states of the game
srigdon3 0:0a900ff9a788 598 void initialize(void)
srigdon3 0:0a900ff9a788 599 {
srigdon3 0:0a900ff9a788 600 drawBORDERS();
srigdon3 0:0a900ff9a788 601 placeCOINS();
srigdon3 0:0a900ff9a788 602 uLCD.filled_circle(x,y,PAC_SIZE,0xFFFF00);
srigdon3 0:0a900ff9a788 603 uLCD.filled_rectangle(x-2,y-2,x-PAC_SIZE,y+2,BLACK);
srigdon3 0:0a900ff9a788 604 }
srigdon3 0:0a900ff9a788 605
srigdon3 1:b86030cf57c4 606 //Check to see if all the coins have been eaten
srigdon3 0:0a900ff9a788 607 void checkWIN(void)
srigdon3 0:0a900ff9a788 608 {
srigdon3 0:0a900ff9a788 609 win = true;
srigdon3 0:0a900ff9a788 610 for(int k=0; k<81; k++)
srigdon3 0:0a900ff9a788 611 {
srigdon3 0:0a900ff9a788 612 lcd_mutex.lock();
srigdon3 1:b86030cf57c4 613 if(coins[k][0]!=64 || coins[k][1]!=64) //Check the locations of all coins and if 1 has coordinates other than (64,64) the user has not won
srigdon3 0:0a900ff9a788 614 {
srigdon3 0:0a900ff9a788 615 win = false;
srigdon3 0:0a900ff9a788 616 }
srigdon3 0:0a900ff9a788 617 lcd_mutex.unlock();
srigdon3 0:0a900ff9a788 618 }
srigdon3 0:0a900ff9a788 619 }
srigdon3 0:0a900ff9a788 620
srigdon3 1:b86030cf57c4 621 //Thread supervising the joystick inputs and moving Pacman accordingly
srigdon3 0:0a900ff9a788 622 void pacMOVE(void const *args)
srigdon3 0:0a900ff9a788 623 {
srigdon3 0:0a900ff9a788 624 while(!win)
srigdon3 0:0a900ff9a788 625 {
srigdon3 0:0a900ff9a788 626 checkMOVE();
srigdon3 0:0a900ff9a788 627 Thread::wait(10);
srigdon3 0:0a900ff9a788 628 }
srigdon3 0:0a900ff9a788 629 }
srigdon3 0:0a900ff9a788 630
srigdon3 1:b86030cf57c4 631 //Thread controlling the movement of the blue ghost
srigdon3 0:0a900ff9a788 632 void blueGHOST(void const *args)
srigdon3 0:0a900ff9a788 633 {
srigdon3 0:0a900ff9a788 634 while(!win)
srigdon3 0:0a900ff9a788 635 {
srigdon3 0:0a900ff9a788 636 pickMOVE();
srigdon3 0:0a900ff9a788 637 }
srigdon3 0:0a900ff9a788 638 }
srigdon3 0:0a900ff9a788 639
srigdon3 0:0a900ff9a788 640 int main()
srigdon3 0:0a900ff9a788 641 {
srigdon3 0:0a900ff9a788 642 uLCD.cls();
srigdon3 0:0a900ff9a788 643 uLCD.baudrate(BAUD_3000000);
srigdon3 1:b86030cf57c4 644 initialize(); //Draw the level setup
srigdon3 1:b86030cf57c4 645 Thread pm(pacMOVE); //Start the thread for moving Pacman
srigdon3 1:b86030cf57c4 646 //Thread bg(blueGHOST); //Start the thread for moving the blue ghost
srigdon3 0:0a900ff9a788 647
srigdon3 1:b86030cf57c4 648 Thread::wait(5000); //Wait some time before checking the win conditions since it will take around 30 secs to eat all 81 coins
srigdon3 1:b86030cf57c4 649 while(!win) //Check to see if there was a win once every tenth of a second
srigdon3 0:0a900ff9a788 650 {
srigdon3 0:0a900ff9a788 651 checkWIN();
srigdon3 1:b86030cf57c4 652 Thread::wait(100);
srigdon3 0:0a900ff9a788 653 }
srigdon3 1:b86030cf57c4 654
srigdon3 1:b86030cf57c4 655 Thread::wait(1000); //Wait one second before displaying end message
srigdon3 1:b86030cf57c4 656
srigdon3 1:b86030cf57c4 657 if(lose) //Print game over message if lose (determined in the follow function)
srigdon3 0:0a900ff9a788 658 {
srigdon3 0:0a900ff9a788 659 uLCD.cls();
srigdon3 0:0a900ff9a788 660 uLCD.printf("Sorry\nGame Over");
srigdon3 0:0a900ff9a788 661 }
srigdon3 0:0a900ff9a788 662 else
srigdon3 0:0a900ff9a788 663 {
srigdon3 0:0a900ff9a788 664 uLCD.cls();
srigdon3 0:0a900ff9a788 665 uLCD.printf("Congratulations!\nYou Won!");
srigdon3 0:0a900ff9a788 666 }
srigdon3 0:0a900ff9a788 667
srigdon3 0:0a900ff9a788 668 while(1){}
srigdon3 0:0a900ff9a788 669 }