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
main.h@28:c0e3de1fd2a6, 2015-05-11 (annotated)
- Committer:
- el13ks
- Date:
- Mon May 11 13:57:06 2015 +0000
- Revision:
- 28:c0e3de1fd2a6
- Parent:
- 27:c1e337f1b99f
Forked N5110 library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el13ks | 17:9a8a6516d63d | 1 | /** |
el13ks | 17:9a8a6516d63d | 2 | @file main.h |
el13ks | 17:9a8a6516d63d | 3 | @brief Header file containing functions prototypes, defines and global variables. |
el13ks | 27:c1e337f1b99f | 4 | @see "Pacman" by Shawn Rigdon |
el13ks | 27:c1e337f1b99f | 5 | @see "Joystick" by Craig Evans |
el13ks | 17:9a8a6516d63d | 6 | @brief Revision 1.0. |
el13ks | 19:e2659a0b91fa | 7 | @author Konlatee Sittichaivijit |
el13ks | 17:9a8a6516d63d | 8 | @date April 2015 |
el13ks | 17:9a8a6516d63d | 9 | */ |
el13ks | 19:e2659a0b91fa | 10 | |
el13ks | 17:9a8a6516d63d | 11 | #ifndef MAIN_H |
el13ks | 17:9a8a6516d63d | 12 | #define MAIN_H |
el13ks | 19:e2659a0b91fa | 13 | #include "mbed.h" |
el13ks | 18:d0900678656a | 14 | #include "N5110.h" |
el13ks | 18:d0900678656a | 15 | #define DIRECTION_TOLERANCE 0.2// Tolerance of Joystick |
el13ks | 18:d0900678656a | 16 | #include "tone.h" |
el13ks | 17:9a8a6516d63d | 17 | #define PI 3.14159265359 |
el13ks | 18:d0900678656a | 18 | #include "PowerControl/PowerControl.h" |
el13ks | 18:d0900678656a | 19 | #include "PowerControl/EthernetPowerControl.h" |
el13ks | 18:d0900678656a | 20 | |
el13ks | 26:4cfeb2c29326 | 21 | |
el13ks | 27:c1e337f1b99f | 22 | /** |
el13ks | 27:c1e337f1b99f | 23 | @namespace LocalFileSystem local("local") |
el13ks | 27:c1e337f1b99f | 24 | @brief Creates a local file on the flash memory of the mbed for high score storage |
el13ks | 27:c1e337f1b99f | 25 | */ |
el13ks | 26:4cfeb2c29326 | 26 | |
el13ks | 27:c1e337f1b99f | 27 | LocalFileSystem local("local"); // define local file system |
el13ks | 26:4cfeb2c29326 | 28 | /** |
el13ks | 26:4cfeb2c29326 | 29 | @namespace PWM3 |
el13ks | 26:4cfeb2c29326 | 30 | @brief Red LED |
el13ks | 26:4cfeb2c29326 | 31 | */ |
el13ks | 26:4cfeb2c29326 | 32 | |
el13ks | 26:4cfeb2c29326 | 33 | |
el13ks | 26:4cfeb2c29326 | 34 | PwmOut PWM3(p24);//Red LED |
el13ks | 26:4cfeb2c29326 | 35 | /** |
el13ks | 26:4cfeb2c29326 | 36 | @namespace PWM2 |
el13ks | 26:4cfeb2c29326 | 37 | @brief Green LED |
el13ks | 26:4cfeb2c29326 | 38 | */ |
el13ks | 26:4cfeb2c29326 | 39 | |
el13ks | 26:4cfeb2c29326 | 40 | PwmOut PWM2(p22);//Green LED |
el13ks | 26:4cfeb2c29326 | 41 | |
el13ks | 26:4cfeb2c29326 | 42 | /** |
el13ks | 26:4cfeb2c29326 | 43 | @namespace PWM1 |
el13ks | 26:4cfeb2c29326 | 44 | @brief yellow LED |
el13ks | 26:4cfeb2c29326 | 45 | */ |
el13ks | 26:4cfeb2c29326 | 46 | |
el13ks | 26:4cfeb2c29326 | 47 | |
el13ks | 26:4cfeb2c29326 | 48 | |
el13ks | 26:4cfeb2c29326 | 49 | PwmOut PWM1(p23); //Yellow LED |
el13ks | 26:4cfeb2c29326 | 50 | /** |
el13ks | 26:4cfeb2c29326 | 51 | @namespace buzzer |
el13ks | 26:4cfeb2c29326 | 52 | @brief Piezo buzzer to output game music |
el13ks | 26:4cfeb2c29326 | 53 | */ |
el13ks | 26:4cfeb2c29326 | 54 | PwmOut buzzer(p25); |
el13ks | 26:4cfeb2c29326 | 55 | |
el13ks | 18:d0900678656a | 56 | /**Starting "i" coordinate for pacman*/ |
el13ks | 19:e2659a0b91fa | 57 | int i=3; |
el13ks | 18:d0900678656a | 58 | /**Starting "j" coordinate for pacman*/ |
el13ks | 18:d0900678656a | 59 | int j = 3; |
el13ks | 25:55331fbafc67 | 60 | /**Flag for Start button*/ |
el13ks | 19:e2659a0b91fa | 61 | int buttonflag=0; |
el13ks | 19:e2659a0b91fa | 62 | /** |
el13ks | 19:e2659a0b91fa | 63 | @namespace bright |
el13ks | 19:e2659a0b91fa | 64 | @brief Potentiometer For LCD brightness adjustment |
el13ks | 19:e2659a0b91fa | 65 | */ |
el13ks | 19:e2659a0b91fa | 66 | AnalogIn bright(p20); |
el13ks | 19:e2659a0b91fa | 67 | /** |
el13ks | 19:e2659a0b91fa | 68 | @namespace timer |
el13ks | 19:e2659a0b91fa | 69 | @brief Timeout object to put mbed into sleep mode and turn off lcd after a period of inactivity |
el13ks | 19:e2659a0b91fa | 70 | */ |
el13ks | 19:e2659a0b91fa | 71 | Timeout timer; //Create timeout object |
el13ks | 19:e2659a0b91fa | 72 | /** |
el13ks | 19:e2659a0b91fa | 73 | @namespace Jbutton |
el13ks | 26:4cfeb2c29326 | 74 | @brief Joystick button for pausing game |
el13ks | 19:e2659a0b91fa | 75 | */ |
el13ks | 19:e2659a0b91fa | 76 | InterruptIn Jbutton(p17);// Joystick Button |
el13ks | 19:e2659a0b91fa | 77 | /** |
el13ks | 19:e2659a0b91fa | 78 | @namespace xPot |
el13ks | 19:e2659a0b91fa | 79 | @brief Joystick x-direction adjustment |
el13ks | 19:e2659a0b91fa | 80 | */ |
el13ks | 19:e2659a0b91fa | 81 | AnalogIn xPot(p15);// Joystick x-direction |
el13ks | 19:e2659a0b91fa | 82 | /** |
el13ks | 19:e2659a0b91fa | 83 | @namespace yPot |
el13ks | 19:e2659a0b91fa | 84 | @brief Joystick y-direction adjustment |
el13ks | 19:e2659a0b91fa | 85 | */ |
el13ks | 19:e2659a0b91fa | 86 | AnalogIn yPot(p16);// Joystick y-direction |
el13ks | 19:e2659a0b91fa | 87 | /** |
el13ks | 19:e2659a0b91fa | 88 | @namespace button |
el13ks | 26:4cfeb2c29326 | 89 | @brief Button to start game |
el13ks | 19:e2659a0b91fa | 90 | */ |
el13ks | 19:e2659a0b91fa | 91 | InterruptIn button(p18);//Pause button |
el13ks | 19:e2659a0b91fa | 92 | /** |
el13ks | 19:e2659a0b91fa | 93 | @namespace pollJoystick |
el13ks | 19:e2659a0b91fa | 94 | @brief Ticker object to regularly read the joystick |
el13ks | 19:e2659a0b91fa | 95 | */ |
el13ks | 19:e2659a0b91fa | 96 | |
el13ks | 19:e2659a0b91fa | 97 | Ticker pollJoystick; // timer to regularly read the joystick |
el13ks | 19:e2659a0b91fa | 98 | /** |
el13ks | 26:4cfeb2c29326 | 99 | @namespace score |
el13ks | 26:4cfeb2c29326 | 100 | @brief Ticker object to count score |
el13ks | 19:e2659a0b91fa | 101 | */ |
el13ks | 19:e2659a0b91fa | 102 | |
el13ks | 26:4cfeb2c29326 | 103 | Ticker score;// ticker object to count the score |
el13ks | 26:4cfeb2c29326 | 104 | /** |
el13ks | 26:4cfeb2c29326 | 105 | @namespace ghost |
el13ks | 26:4cfeb2c29326 | 106 | @brief Ticker object to regularly update the ghost |
el13ks | 26:4cfeb2c29326 | 107 | */ |
el13ks | 26:4cfeb2c29326 | 108 | |
el13ks | 26:4cfeb2c29326 | 109 | |
el13ks | 26:4cfeb2c29326 | 110 | |
el13ks | 26:4cfeb2c29326 | 111 | Ticker ghost;// Ticker object to update ghost |
el13ks | 26:4cfeb2c29326 | 112 | |
el13ks | 19:e2659a0b91fa | 113 | |
el13ks | 19:e2659a0b91fa | 114 | |
el13ks | 25:55331fbafc67 | 115 | /**Flag for pause button*/ |
el13ks | 19:e2659a0b91fa | 116 | |
el13ks | 19:e2659a0b91fa | 117 | int buttonflag1=0; |
el13ks | 26:4cfeb2c29326 | 118 | /**Flag for ghost movement*/ |
el13ks | 26:4cfeb2c29326 | 119 | int followflag=0;// flag for ghost to follow pacman |
el13ks | 19:e2659a0b91fa | 120 | |
el13ks | 26:4cfeb2c29326 | 121 | /**Buffer to print new player score*/ |
el13ks | 19:e2659a0b91fa | 122 | |
el13ks | 26:4cfeb2c29326 | 123 | char buffer[14];// buffer for printing latest player score |
el13ks | 26:4cfeb2c29326 | 124 | /**Buffer to print high score*/ |
el13ks | 26:4cfeb2c29326 | 125 | char buffer1[14];// buffer for printing high score |
el13ks | 26:4cfeb2c29326 | 126 | /**int for starting score, decreases every 1 second */ |
el13ks | 26:4cfeb2c29326 | 127 | int e =1000;// Starting score, decreases by 1 every second |
el13ks | 26:4cfeb2c29326 | 128 | /**int to store highscore*/ |
el13ks | 26:4cfeb2c29326 | 129 | int score1;// int for high score |
el13ks | 19:e2659a0b91fa | 130 | |
el13ks | 26:4cfeb2c29326 | 131 | /**Flag for updating score */ |
el13ks | 26:4cfeb2c29326 | 132 | int scoreflag=0;// flag for score function |
el13ks | 19:e2659a0b91fa | 133 | /** @namespace N5110lcd |
el13ks | 19:e2659a0b91fa | 134 | @brief Create a N5110 object connected to the specified pins |
el13ks | 19:e2659a0b91fa | 135 | */ |
el13ks | 19:e2659a0b91fa | 136 | N5110 lcd(p7,p8,p9,p10,p11,p13,p26); //PWR, SCE, RST, DC, MOSI, SCLK, LED |
el13ks | 19:e2659a0b91fa | 137 | /** Boolean Variable for winning condition |
el13ks | 19:e2659a0b91fa | 138 | */ |
el13ks | 19:e2659a0b91fa | 139 | volatile bool win=false; |
el13ks | 19:e2659a0b91fa | 140 | /** Boolean Variable for losing condition |
el13ks | 19:e2659a0b91fa | 141 | */ |
el13ks | 19:e2659a0b91fa | 142 | volatile bool lose= false; |
el13ks | 19:e2659a0b91fa | 143 | /** Starting "i" coordinate for ghost |
el13ks | 19:e2659a0b91fa | 144 | */ |
el13ks | 19:e2659a0b91fa | 145 | |
el13ks | 19:e2659a0b91fa | 146 | int x=67; // Ghost starting position |
el13ks | 19:e2659a0b91fa | 147 | /** Starting "j" coordinate for ghost |
el13ks | 19:e2659a0b91fa | 148 | */ |
el13ks | 19:e2659a0b91fa | 149 | int y = 44; |
el13ks | 19:e2659a0b91fa | 150 | /** Flag for timeout object |
el13ks | 19:e2659a0b91fa | 151 | */ |
el13ks | 19:e2659a0b91fa | 152 | int timerflag=0;// flag for timeout function |
el13ks | 19:e2659a0b91fa | 153 | /** Variable for starting number of coins, if this variable reaches 0, the user wins the game |
el13ks | 19:e2659a0b91fa | 154 | */ |
el13ks | 19:e2659a0b91fa | 155 | int w=28;// winning condition variable |
el13ks | 26:4cfeb2c29326 | 156 | |
el13ks | 26:4cfeb2c29326 | 157 | |
el13ks | 26:4cfeb2c29326 | 158 | |
el13ks | 26:4cfeb2c29326 | 159 | /** An array for beat of music notes |
el13ks | 26:4cfeb2c29326 | 160 | */ |
el13ks | 26:4cfeb2c29326 | 161 | |
el13ks | 26:4cfeb2c29326 | 162 | |
el13ks | 26:4cfeb2c29326 | 163 | |
el13ks | 26:4cfeb2c29326 | 164 | 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,1,1}; //beat arrayfor pacman soundtrack |
el13ks | 26:4cfeb2c29326 | 165 | |
el13ks | 26:4cfeb2c29326 | 166 | /** An array for frequency of music notes |
el13ks | 26:4cfeb2c29326 | 167 | */ |
el13ks | 26:4cfeb2c29326 | 168 | |
el13ks | 26:4cfeb2c29326 | 169 | |
el13ks | 26:4cfeb2c29326 | 170 | |
el13ks | 26:4cfeb2c29326 | 171 | 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 for pacman soundtrack |
el13ks | 19:e2659a0b91fa | 172 | /** An array indicating the location of each coin |
el13ks | 19:e2659a0b91fa | 173 | */ |
el13ks | 19:e2659a0b91fa | 174 | int coins[28][2] = { // array for location of coins |
el13ks | 19:e2659a0b91fa | 175 | {10,3},{22,3},{35,3},{47,3},{65,3},{80,3}, |
el13ks | 19:e2659a0b91fa | 176 | {41,14}, |
el13ks | 20:874b009fea11 | 177 | {3,13},{13,15},{65,15},{80,14}, |
el13ks | 23:e7f69bc42b29 | 178 | {7,24},{18,24},{34,24},{47,24},{62,24},{74,24}, |
el13ks | 20:874b009fea11 | 179 | {7,33},{23,34},{41,33},{61,34},{74,33}, |
el13ks | 19:e2659a0b91fa | 180 | {7,44},{21,44},{35,44},{47,44},{61,44},{74,44} |
el13ks | 19:e2659a0b91fa | 181 | }; |
el13ks | 19:e2659a0b91fa | 182 | /** Enumerated type for direction |
el13ks | 19:e2659a0b91fa | 183 | */ |
el13ks | 19:e2659a0b91fa | 184 | enum DirectionName { // create enumerated type (0,1,2,3 etc. for direction) |
el13ks | 19:e2659a0b91fa | 185 | UP, // could be extended for diagonals etc. |
el13ks | 19:e2659a0b91fa | 186 | DOWN, |
el13ks | 19:e2659a0b91fa | 187 | LEFT, |
el13ks | 19:e2659a0b91fa | 188 | RIGHT, |
el13ks | 19:e2659a0b91fa | 189 | CENTRE, |
el13ks | 19:e2659a0b91fa | 190 | UNKNOWN |
el13ks | 19:e2659a0b91fa | 191 | }; |
el13ks | 19:e2659a0b91fa | 192 | /** Creates a type definition struct for the joystick |
el13ks | 19:e2659a0b91fa | 193 | */ |
el13ks | 19:e2659a0b91fa | 194 | |
el13ks | 19:e2659a0b91fa | 195 | |
el13ks | 19:e2659a0b91fa | 196 | typedef struct JoyStick Joystick; // struct for Joystick |
el13ks | 19:e2659a0b91fa | 197 | |
el13ks | 19:e2659a0b91fa | 198 | |
el13ks | 19:e2659a0b91fa | 199 | |
el13ks | 19:e2659a0b91fa | 200 | |
el13ks | 19:e2659a0b91fa | 201 | |
el13ks | 19:e2659a0b91fa | 202 | /** Creates a struct object for the joystick |
el13ks | 19:e2659a0b91fa | 203 | */ |
el13ks | 19:e2659a0b91fa | 204 | |
el13ks | 19:e2659a0b91fa | 205 | struct JoyStick { |
el13ks | 19:e2659a0b91fa | 206 | float x; // current x value |
el13ks | 19:e2659a0b91fa | 207 | float x0; // 'centred' x value |
el13ks | 19:e2659a0b91fa | 208 | float y; // current y value |
el13ks | 19:e2659a0b91fa | 209 | float y0; // 'centred' y value |
el13ks | 19:e2659a0b91fa | 210 | int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) |
el13ks | 19:e2659a0b91fa | 211 | DirectionName direction; // current direction |
el13ks | 19:e2659a0b91fa | 212 | }; |
el13ks | 19:e2659a0b91fa | 213 | |
el13ks | 19:e2659a0b91fa | 214 | /** Create struct variable |
el13ks | 19:e2659a0b91fa | 215 | */ |
el13ks | 19:e2659a0b91fa | 216 | |
el13ks | 19:e2659a0b91fa | 217 | Joystick joystick; // create struct variable |
el13ks | 26:4cfeb2c29326 | 218 | /** Credit screen to be displayed at end of game |
el13ks | 26:4cfeb2c29326 | 219 | */ |
el13ks | 26:4cfeb2c29326 | 220 | void creditscreen(); |
el13ks | 26:4cfeb2c29326 | 221 | /** Outputs pacman sountrack |
el13ks | 26:4cfeb2c29326 | 222 | @param q - integer to store which note is playing |
el13ks | 26:4cfeb2c29326 | 223 | */ |
el13ks | 26:4cfeb2c29326 | 224 | void tune(); |
el13ks | 26:4cfeb2c29326 | 225 | /** Compares repsective position of ghost and pacman, and the ghost chases pacman |
el13ks | 26:4cfeb2c29326 | 226 | @param y - Current y-position of the ghost |
el13ks | 26:4cfeb2c29326 | 227 | @param x - Current x-position of the ghost |
el13ks | 26:4cfeb2c29326 | 228 | @param j - Current y-position of the pacman |
el13ks | 26:4cfeb2c29326 | 229 | @param i - Current x-position of the pacman |
el13ks | 26:4cfeb2c29326 | 230 | |
el13ks | 26:4cfeb2c29326 | 231 | */ |
el13ks | 26:4cfeb2c29326 | 232 | |
el13ks | 26:4cfeb2c29326 | 233 | void ghostfollow(); |
el13ks | 26:4cfeb2c29326 | 234 | /** Set the scoreflag |
el13ks | 26:4cfeb2c29326 | 235 | @param scoreflag - flag to be set for updating score |
el13ks | 26:4cfeb2c29326 | 236 | |
el13ks | 26:4cfeb2c29326 | 237 | */ |
el13ks | 26:4cfeb2c29326 | 238 | |
el13ks | 26:4cfeb2c29326 | 239 | |
el13ks | 26:4cfeb2c29326 | 240 | void scoreexpired(); |
el13ks | 26:4cfeb2c29326 | 241 | /** Set the followflag |
el13ks | 26:4cfeb2c29326 | 242 | @param followflag - flag to be set for updating the ghost |
el13ks | 26:4cfeb2c29326 | 243 | |
el13ks | 26:4cfeb2c29326 | 244 | */ |
el13ks | 26:4cfeb2c29326 | 245 | void ghosttimerexpired(); |
el13ks | 26:4cfeb2c29326 | 246 | |
el13ks | 19:e2659a0b91fa | 247 | /** Defaults the current position of the joystick |
el13ks | 19:e2659a0b91fa | 248 | @param xPot - Current x-position of the joystick |
el13ks | 19:e2659a0b91fa | 249 | @param yPot - Current y-position of the joystick |
el13ks | 19:e2659a0b91fa | 250 | @param joystick.x0 - Defaulted position of xPot |
el13ks | 19:e2659a0b91fa | 251 | @param joystick.y0 - Defaulted position of yPot |
el13ks | 19:e2659a0b91fa | 252 | @param button.mode(PullDown)- Define mode of joystci button |
el13ks | 19:e2659a0b91fa | 253 | */ |
el13ks | 19:e2659a0b91fa | 254 | void calibrateJoystick(); |
el13ks | 19:e2659a0b91fa | 255 | /** Reads current position of joystick and compare it to the defaulted values |
el13ks | 19:e2659a0b91fa | 256 | @param joystick.x - Read current position of joystick in x-axis |
el13ks | 19:e2659a0b91fa | 257 | @param joystick.y - Read current position of joystick in x-axis |
el13ks | 19:e2659a0b91fa | 258 | @param joystick.button- Reads current state of joystick button |
el13ks | 19:e2659a0b91fa | 259 | @param joystick.direction- Defines the direction of joystick |
el13ks | 19:e2659a0b91fa | 260 | */ |
el13ks | 19:e2659a0b91fa | 261 | void updateJoystick(); |
el13ks | 19:e2659a0b91fa | 262 | /** Moves the player in the direction of the joystick |
el13ks | 19:e2659a0b91fa | 263 | |
el13ks | 19:e2659a0b91fa | 264 | */ |
el13ks | 19:e2659a0b91fa | 265 | |
el13ks | 19:e2659a0b91fa | 266 | |
el13ks | 19:e2659a0b91fa | 267 | void Joystickcheck(); |
el13ks | 19:e2659a0b91fa | 268 | /** Sets the timerflag |
el13ks | 19:e2659a0b91fa | 269 | @param timerflag - flag to be set |
el13ks | 19:e2659a0b91fa | 270 | |
el13ks | 19:e2659a0b91fa | 271 | */ |
el13ks | 19:e2659a0b91fa | 272 | |
el13ks | 19:e2659a0b91fa | 273 | void timerExpired(); |
el13ks | 19:e2659a0b91fa | 274 | /** Set or reset the buttonflag |
el13ks | 19:e2659a0b91fa | 275 | @param buttonflag - flag to be set |
el13ks | 19:e2659a0b91fa | 276 | |
el13ks | 19:e2659a0b91fa | 277 | */ |
el13ks | 19:e2659a0b91fa | 278 | |
el13ks | 19:e2659a0b91fa | 279 | void pressPause(); |
el13ks | 19:e2659a0b91fa | 280 | /** Pauses the game if button is pressed |
el13ks | 19:e2659a0b91fa | 281 | Takes user to pause screen |
el13ks | 19:e2659a0b91fa | 282 | After 15 seconds of inactivity in the pause screen, the mbed enters sleep mode and lcd powers down |
el13ks | 19:e2659a0b91fa | 283 | Press the pause button to wake the device back up |
el13ks | 19:e2659a0b91fa | 284 | |
el13ks | 19:e2659a0b91fa | 285 | |
el13ks | 19:e2659a0b91fa | 286 | */ |
el13ks | 19:e2659a0b91fa | 287 | void pause(); |
el13ks | 19:e2659a0b91fa | 288 | /** Draws Map |
el13ks | 19:e2659a0b91fa | 289 | Obstacles are drawn using the drawRect function |
el13ks | 26:4cfeb2c29326 | 290 | */ |
el13ks | 26:4cfeb2c29326 | 291 | void drawMap(); |
el13ks | 19:e2659a0b91fa | 292 | |
el13ks | 19:e2659a0b91fa | 293 | |
el13ks | 26:4cfeb2c29326 | 294 | /** Function to draw pacman during wasted mode, and ensures he faces the direction of travel |
el13ks | 26:4cfeb2c29326 | 295 | All relevant pixels set with reference to "i" and "j" |
el13ks | 26:4cfeb2c29326 | 296 | @param i-location of centre of pacman |
el13ks | 26:4cfeb2c29326 | 297 | @param j-location of centre of pacman |
el13ks | 26:4cfeb2c29326 | 298 | |
el13ks | 19:e2659a0b91fa | 299 | */ |
el13ks | 26:4cfeb2c29326 | 300 | |
el13ks | 26:4cfeb2c29326 | 301 | void drawPacman2(); |
el13ks | 19:e2659a0b91fa | 302 | /** Check to see if there are any obstacles to the right of the player |
el13ks | 19:e2659a0b91fa | 303 | Each pixel found to the right adds 1 to r |
el13ks | 19:e2659a0b91fa | 304 | If there are more than a set number of pixels, player cannot move further in that direction |
el13ks | 19:e2659a0b91fa | 305 | @param r - variable to count the number of pixels to the right |
el13ks | 19:e2659a0b91fa | 306 | |
el13ks | 19:e2659a0b91fa | 307 | |
el13ks | 19:e2659a0b91fa | 308 | */ |
el13ks | 19:e2659a0b91fa | 309 | |
el13ks | 19:e2659a0b91fa | 310 | |
el13ks | 19:e2659a0b91fa | 311 | void checkRight(); |
el13ks | 19:e2659a0b91fa | 312 | /** Check to see if there are any obstacles to the left of the player |
el13ks | 19:e2659a0b91fa | 313 | Each pixel found to the right adds 1 to l |
el13ks | 19:e2659a0b91fa | 314 | If there are more than a set number of pixels, player cannot move further in that direction |
el13ks | 19:e2659a0b91fa | 315 | @param l - variable to count the number of pixels to the left |
el13ks | 19:e2659a0b91fa | 316 | |
el13ks | 19:e2659a0b91fa | 317 | |
el13ks | 19:e2659a0b91fa | 318 | */ |
el13ks | 19:e2659a0b91fa | 319 | void checkLeft(); |
el13ks | 19:e2659a0b91fa | 320 | /** Check to see if there are any obstacles above the player |
el13ks | 19:e2659a0b91fa | 321 | Each pixel found to the right adds 1 to u |
el13ks | 19:e2659a0b91fa | 322 | If there are more than a set number of pixels, player cannot move further in that direction |
el13ks | 19:e2659a0b91fa | 323 | @param u - variable to count the number of pixels above |
el13ks | 19:e2659a0b91fa | 324 | |
el13ks | 19:e2659a0b91fa | 325 | |
el13ks | 19:e2659a0b91fa | 326 | */ |
el13ks | 19:e2659a0b91fa | 327 | |
el13ks | 19:e2659a0b91fa | 328 | |
el13ks | 19:e2659a0b91fa | 329 | void checkUp(); |
el13ks | 19:e2659a0b91fa | 330 | /** Check to see if there are any obstacles below the player |
el13ks | 19:e2659a0b91fa | 331 | Each pixel found to the right adds 1 to d |
el13ks | 19:e2659a0b91fa | 332 | If there are more than a set number of pixels, player cannot move further in that direction |
el13ks | 19:e2659a0b91fa | 333 | @param d - variable to count the number of pixels below |
el13ks | 19:e2659a0b91fa | 334 | */ |
el13ks | 19:e2659a0b91fa | 335 | void checkDown(); |
el13ks | 19:e2659a0b91fa | 336 | /** Function to draw coins in the locations specified in the coin array |
el13ks | 19:e2659a0b91fa | 337 | |
el13ks | 19:e2659a0b91fa | 338 | @param k - integer to count the number of coins drawn |
el13ks | 19:e2659a0b91fa | 339 | */ |
el13ks | 19:e2659a0b91fa | 340 | |
el13ks | 19:e2659a0b91fa | 341 | |
el13ks | 19:e2659a0b91fa | 342 | void drawCoin(void); |
el13ks | 19:e2659a0b91fa | 343 | /** Function to check whether coins have been eaten |
el13ks | 19:e2659a0b91fa | 344 | If so, the coin disappears, and 1 is subtracted from "w" |
el13ks | 19:e2659a0b91fa | 345 | |
el13ks | 19:e2659a0b91fa | 346 | @param w - integer to count the number of coins uneaten |
el13ks | 19:e2659a0b91fa | 347 | */ |
el13ks | 19:e2659a0b91fa | 348 | |
el13ks | 19:e2659a0b91fa | 349 | |
el13ks | 19:e2659a0b91fa | 350 | |
el13ks | 19:e2659a0b91fa | 351 | void checkCoin(); |
el13ks | 19:e2659a0b91fa | 352 | /** Function to draw pacman, and ensures he faces the direction of travel |
el13ks | 19:e2659a0b91fa | 353 | All relevant pixels set with reference to "i" and "j" |
el13ks | 19:e2659a0b91fa | 354 | @param i-location of centre of pacman |
el13ks | 19:e2659a0b91fa | 355 | @param j-location of centre of pacman |
el13ks | 19:e2659a0b91fa | 356 | |
el13ks | 19:e2659a0b91fa | 357 | */ |
el13ks | 19:e2659a0b91fa | 358 | |
el13ks | 19:e2659a0b91fa | 359 | |
el13ks | 19:e2659a0b91fa | 360 | void drawPacman(); |
el13ks | 19:e2659a0b91fa | 361 | /** Function to draw ghost |
el13ks | 19:e2659a0b91fa | 362 | All relevant pixels set with reference to "x" and "y" |
el13ks | 19:e2659a0b91fa | 363 | @param x-location of centre of ghost |
el13ks | 19:e2659a0b91fa | 364 | @param y-location of centre of ghost |
el13ks | 19:e2659a0b91fa | 365 | |
el13ks | 19:e2659a0b91fa | 366 | */ |
el13ks | 19:e2659a0b91fa | 367 | |
el13ks | 19:e2659a0b91fa | 368 | |
el13ks | 19:e2659a0b91fa | 369 | void drawGhost(); |
el13ks | 19:e2659a0b91fa | 370 | /** Ensures that player cannot move off screen |
el13ks | 19:e2659a0b91fa | 371 | |
el13ks | 19:e2659a0b91fa | 372 | |
el13ks | 19:e2659a0b91fa | 373 | */ |
el13ks | 19:e2659a0b91fa | 374 | |
el13ks | 19:e2659a0b91fa | 375 | |
el13ks | 19:e2659a0b91fa | 376 | void Boundarycheck(); |
el13ks | 19:e2659a0b91fa | 377 | /** Checks if all coins have been eaten |
el13ks | 19:e2659a0b91fa | 378 | |
el13ks | 19:e2659a0b91fa | 379 | |
el13ks | 19:e2659a0b91fa | 380 | |
el13ks | 19:e2659a0b91fa | 381 | */ |
el13ks | 19:e2659a0b91fa | 382 | |
el13ks | 19:e2659a0b91fa | 383 | |
el13ks | 19:e2659a0b91fa | 384 | void winningcondition(); |
el13ks | 19:e2659a0b91fa | 385 | /** Checks if ghost has eaten pacman |
el13ks | 19:e2659a0b91fa | 386 | |
el13ks | 19:e2659a0b91fa | 387 | |
el13ks | 19:e2659a0b91fa | 388 | |
el13ks | 19:e2659a0b91fa | 389 | */ |
el13ks | 19:e2659a0b91fa | 390 | |
el13ks | 19:e2659a0b91fa | 391 | |
el13ks | 19:e2659a0b91fa | 392 | |
el13ks | 19:e2659a0b91fa | 393 | void losingcondition(); |
el13ks | 26:4cfeb2c29326 | 394 | |
el13ks | 26:4cfeb2c29326 | 395 | /** Adds 1 to buttonflag1 |
el13ks | 20:874b009fea11 | 396 | |
el13ks | 26:4cfeb2c29326 | 397 | @param buttonflag1 - flag for direction start button |
el13ks | 26:4cfeb2c29326 | 398 | */ |
el13ks | 26:4cfeb2c29326 | 399 | void pressStart(); |
el13ks | 26:4cfeb2c29326 | 400 | |
el13ks | 26:4cfeb2c29326 | 401 | /** Moves player in opposite way to joystick direction |
el13ks | 20:874b009fea11 | 402 | |
el13ks | 20:874b009fea11 | 403 | |
el13ks | 20:874b009fea11 | 404 | */ |
el13ks | 20:874b009fea11 | 405 | |
el13ks | 20:874b009fea11 | 406 | |
el13ks | 26:4cfeb2c29326 | 407 | void Wastedmode(); |
el13ks | 26:4cfeb2c29326 | 408 | /** Check to see whethert the direction swap button has been pressed |
el13ks | 26:4cfeb2c29326 | 409 | If so, pacman will start moving in opposite direction to joystick |
el13ks | 26:4cfeb2c29326 | 410 | If not pacman continues to move in direction of joystick |
el13ks | 26:4cfeb2c29326 | 411 | |
el13ks | 26:4cfeb2c29326 | 412 | |
el13ks | 26:4cfeb2c29326 | 413 | */ |
el13ks | 26:4cfeb2c29326 | 414 | |
el13ks | 26:4cfeb2c29326 | 415 | void WastedCheck(); |
el13ks | 26:4cfeb2c29326 | 416 | |
el13ks | 26:4cfeb2c29326 | 417 | /** Displayes start screen |
el13ks | 26:4cfeb2c29326 | 418 | Remain in start screen until start button is pressed |
el13ks | 26:4cfeb2c29326 | 419 | LEDs light up as count down towards start of game |
el13ks | 26:4cfeb2c29326 | 420 | @param buttonflag1 - flag for direction start button |
el13ks | 26:4cfeb2c29326 | 421 | |
el13ks | 26:4cfeb2c29326 | 422 | |
el13ks | 20:874b009fea11 | 423 | */ |
el13ks | 20:874b009fea11 | 424 | |
el13ks | 20:874b009fea11 | 425 | |
el13ks | 20:874b009fea11 | 426 | |
el13ks | 26:4cfeb2c29326 | 427 | void startscreen(); |
el13ks | 20:874b009fea11 | 428 | |
el13ks | 20:874b009fea11 | 429 | |
el13ks | 19:e2659a0b91fa | 430 | |
el13ks | 26:4cfeb2c29326 | 431 | /** Open local file "/local/pacmanScore.txt","w" |
el13ks | 26:4cfeb2c29326 | 432 | Overwrites high score with current score |
el13ks | 26:4cfeb2c29326 | 433 | @param e - Current score |
el13ks | 19:e2659a0b91fa | 434 | |
el13ks | 26:4cfeb2c29326 | 435 | */ |
el13ks | 26:4cfeb2c29326 | 436 | void writeScore(); |
el13ks | 26:4cfeb2c29326 | 437 | /** Open local file "/local/pacmanScore.txt","w" |
el13ks | 26:4cfeb2c29326 | 438 | Reads stored high score |
el13ks | 26:4cfeb2c29326 | 439 | Stores read score in buffer |
el13ks | 26:4cfeb2c29326 | 440 | @param score1 - Previously stored high score |
el13ks | 26:4cfeb2c29326 | 441 | @param buffer1 - buffer to store high score that was read off flash memory |
el13ks | 26:4cfeb2c29326 | 442 | |
el13ks | 26:4cfeb2c29326 | 443 | */ |
el13ks | 26:4cfeb2c29326 | 444 | void readScore(); |
el13ks | 26:4cfeb2c29326 | 445 | /** Compares new score to high score |
el13ks | 26:4cfeb2c29326 | 446 | If new score is higher than stored highscore, overwrite new score |
el13ks | 26:4cfeb2c29326 | 447 | If new score is lower that stored highscore, display both scores |
el13ks | 26:4cfeb2c29326 | 448 | @param score1 - Previously stored high score |
el13ks | 26:4cfeb2c29326 | 449 | @param buffer1 - buffer to store high score that was read off flash memory |
el13ks | 26:4cfeb2c29326 | 450 | @param buffer - buffer to store new score |
el13ks | 26:4cfeb2c29326 | 451 | @param e - Current score |
el13ks | 26:4cfeb2c29326 | 452 | */ |
el13ks | 19:e2659a0b91fa | 453 | |
el13ks | 19:e2659a0b91fa | 454 | |
el13ks | 19:e2659a0b91fa | 455 | |
el13ks | 26:4cfeb2c29326 | 456 | void compareScore(); |
el13ks | 18:d0900678656a | 457 | #endif |