Multi-game multiplayer arcade gaming system meant for the blue O when playing Super Tic-Tac-Toe.
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed wave_player
Stage.h@2:da0f01fbd25c, 2015-12-04 (annotated)
- Committer:
- soapy12312
- Date:
- Fri Dec 04 23:00:42 2015 +0000
- Revision:
- 2:da0f01fbd25c
- Parent:
- 0:218d3fb75950
Multi-game multiplayer arcade gaming system meant for the blue O when playing Super Tic-Tac-Toe.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soapy12312 | 0:218d3fb75950 | 1 | /****************************************************** |
soapy12312 | 0:218d3fb75950 | 2 | * This header file declares all the functions and |
soapy12312 | 2:da0f01fbd25c | 3 | * variables used by the virtual stage in Pac-Man. |
soapy12312 | 0:218d3fb75950 | 4 | ******************************************************/ |
soapy12312 | 0:218d3fb75950 | 5 | |
soapy12312 | 0:218d3fb75950 | 6 | |
soapy12312 | 0:218d3fb75950 | 7 | #define FACERIGHT 0 |
soapy12312 | 0:218d3fb75950 | 8 | #define FACEDOWN 1 |
soapy12312 | 0:218d3fb75950 | 9 | #define FACELEFT 2 |
soapy12312 | 0:218d3fb75950 | 10 | #define FACEUP 3 |
soapy12312 | 0:218d3fb75950 | 11 | |
soapy12312 | 0:218d3fb75950 | 12 | |
soapy12312 | 0:218d3fb75950 | 13 | // Stage class |
soapy12312 | 0:218d3fb75950 | 14 | class Stage { |
soapy12312 | 0:218d3fb75950 | 15 | public: |
soapy12312 | 0:218d3fb75950 | 16 | // Stage constructor |
soapy12312 | 0:218d3fb75950 | 17 | Stage(uLCD_4DGL& uLCD) : uLCD(uLCD) { |
soapy12312 | 0:218d3fb75950 | 18 | } |
soapy12312 | 0:218d3fb75950 | 19 | |
soapy12312 | 0:218d3fb75950 | 20 | // Set up the stage |
soapy12312 | 0:218d3fb75950 | 21 | void initialize() { |
soapy12312 | 0:218d3fb75950 | 22 | printCounters(); |
soapy12312 | 0:218d3fb75950 | 23 | drawStage(); |
soapy12312 | 0:218d3fb75950 | 24 | setPositions(); |
soapy12312 | 0:218d3fb75950 | 25 | } |
soapy12312 | 0:218d3fb75950 | 26 | |
soapy12312 | 0:218d3fb75950 | 27 | // Check if the position is valid |
soapy12312 | 0:218d3fb75950 | 28 | bool checkValid(int xCoordinate, int yCoordinate) { |
soapy12312 | 0:218d3fb75950 | 29 | return (positions[xCoordinate][yCoordinate] != 0); |
soapy12312 | 0:218d3fb75950 | 30 | } |
soapy12312 | 0:218d3fb75950 | 31 | |
soapy12312 | 0:218d3fb75950 | 32 | // Get the valid positions of the players |
soapy12312 | 0:218d3fb75950 | 33 | char* getPositions() { |
soapy12312 | 0:218d3fb75950 | 34 | return *positions; |
soapy12312 | 0:218d3fb75950 | 35 | } |
soapy12312 | 0:218d3fb75950 | 36 | |
soapy12312 | 0:218d3fb75950 | 37 | // Get the number of pac dots |
soapy12312 | 0:218d3fb75950 | 38 | int getPacDots() { |
soapy12312 | 0:218d3fb75950 | 39 | return pacDots; |
soapy12312 | 0:218d3fb75950 | 40 | } |
soapy12312 | 0:218d3fb75950 | 41 | |
soapy12312 | 0:218d3fb75950 | 42 | // Get the number of big pac dots |
soapy12312 | 0:218d3fb75950 | 43 | int getBigPacDots() { |
soapy12312 | 0:218d3fb75950 | 44 | return bigPacDots; |
soapy12312 | 0:218d3fb75950 | 45 | } |
soapy12312 | 0:218d3fb75950 | 46 | |
soapy12312 | 0:218d3fb75950 | 47 | |
soapy12312 | 0:218d3fb75950 | 48 | private: |
soapy12312 | 0:218d3fb75950 | 49 | // Total number of pac dots |
soapy12312 | 0:218d3fb75950 | 50 | int pacDots; |
soapy12312 | 0:218d3fb75950 | 51 | // Total number of big pac dots |
soapy12312 | 0:218d3fb75950 | 52 | int bigPacDots; |
soapy12312 | 0:218d3fb75950 | 53 | // Invalid = 0, valid = 1, pac dot = 2, big pac dot = 3 |
soapy12312 | 0:218d3fb75950 | 54 | char positions[128][128]; |
soapy12312 | 0:218d3fb75950 | 55 | // uLCD display |
soapy12312 | 0:218d3fb75950 | 56 | uLCD_4DGL& uLCD; |
soapy12312 | 0:218d3fb75950 | 57 | // Set Pacman as a friend class |
soapy12312 | 0:218d3fb75950 | 58 | friend class Pacman; |
soapy12312 | 0:218d3fb75950 | 59 | // Set Ghost as a friend class |
soapy12312 | 0:218d3fb75950 | 60 | friend class Ghost; |
soapy12312 | 0:218d3fb75950 | 61 | |
soapy12312 | 0:218d3fb75950 | 62 | // Print score and power-up counters |
soapy12312 | 0:218d3fb75950 | 63 | void printCounters() { |
soapy12312 | 0:218d3fb75950 | 64 | uLCD.printf("Score Power-Up %%"); |
soapy12312 | 0:218d3fb75950 | 65 | } |
soapy12312 | 0:218d3fb75950 | 66 | |
soapy12312 | 0:218d3fb75950 | 67 | // Draw the bounds of the maze |
soapy12312 | 0:218d3fb75950 | 68 | void drawStage() { |
soapy12312 | 0:218d3fb75950 | 69 | uLCD.pixel(108, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 70 | uLCD.pixel(20, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 71 | uLCD.pixel(68, 24, BLUE); |
soapy12312 | 0:218d3fb75950 | 72 | uLCD.pixel(60, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 73 | uLCD.line(4, 16, 60, 16, BLUE); |
soapy12312 | 0:218d3fb75950 | 74 | uLCD.line(68, 16, 124, 16, BLUE); |
soapy12312 | 0:218d3fb75950 | 75 | uLCD.line(60, 16, 60, 24, BLUE); |
soapy12312 | 0:218d3fb75950 | 76 | uLCD.line(68, 16, 68, 24, BLUE); |
soapy12312 | 0:218d3fb75950 | 77 | uLCD.line(60, 24, 68, 24, BLUE); |
soapy12312 | 0:218d3fb75950 | 78 | uLCD.line(4, 16, 4, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 79 | uLCD.line(4, 40, 20, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 80 | uLCD.line(20, 40, 20, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 81 | uLCD.line(4, 64, 20, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 82 | uLCD.line(4, 72, 20, 72, BLUE); |
soapy12312 | 0:218d3fb75950 | 83 | uLCD.line(20, 72, 20, 96, BLUE); |
soapy12312 | 0:218d3fb75950 | 84 | uLCD.line(20, 96, 4, 96, BLUE); |
soapy12312 | 0:218d3fb75950 | 85 | uLCD.line(4, 96, 4, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 86 | uLCD.line(4, 120, 60, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 87 | uLCD.line(124, 16, 124, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 88 | uLCD.line(124, 40, 108, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 89 | uLCD.line(108, 40, 108, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 90 | uLCD.line(124, 64, 108, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 91 | uLCD.line(124, 72, 108, 72, BLUE); |
soapy12312 | 0:218d3fb75950 | 92 | uLCD.line(108, 72, 108, 96, BLUE); |
soapy12312 | 0:218d3fb75950 | 93 | uLCD.line(108, 96, 124, 96, BLUE); |
soapy12312 | 0:218d3fb75950 | 94 | uLCD.line(124, 96, 124, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 95 | uLCD.line(124, 120, 68, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 96 | uLCD.line(68, 120, 68, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 97 | uLCD.line(68, 112, 60, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 98 | uLCD.line(60, 112, 60, 120, BLUE); |
soapy12312 | 0:218d3fb75950 | 99 | uLCD.rectangle(12, 24, 20, 32, BLUE); |
soapy12312 | 0:218d3fb75950 | 100 | uLCD.rectangle(28, 24, 52, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 101 | uLCD.rectangle(76, 24, 100, 40, BLUE); |
soapy12312 | 0:218d3fb75950 | 102 | uLCD.rectangle(108, 24, 116, 32, BLUE); |
soapy12312 | 0:218d3fb75950 | 103 | uLCD.rectangle(28, 48, 44, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 104 | uLCD.rectangle(84, 48, 100, 64, BLUE); |
soapy12312 | 0:218d3fb75950 | 105 | uLCD.rectangle(28, 72, 44, 88, BLUE); |
soapy12312 | 0:218d3fb75950 | 106 | uLCD.rectangle(84, 72, 100, 88, BLUE); |
soapy12312 | 0:218d3fb75950 | 107 | uLCD.rectangle(52, 64, 76, 72, BLUE); |
soapy12312 | 0:218d3fb75950 | 108 | uLCD.line(61, 64, 68, 64, PINK); |
soapy12312 | 0:218d3fb75950 | 109 | uLCD.pixel(61, 64, PINK); |
soapy12312 | 0:218d3fb75950 | 110 | uLCD.pixel(68, 64, PINK); |
soapy12312 | 0:218d3fb75950 | 111 | uLCD.rectangle(12, 104, 20, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 112 | uLCD.rectangle(28, 96, 52, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 113 | uLCD.rectangle(76, 96, 100, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 114 | uLCD.rectangle(108, 104, 116, 112, BLUE); |
soapy12312 | 0:218d3fb75950 | 115 | uLCD.rectangle(60, 32, 68, 56, BLUE); |
soapy12312 | 0:218d3fb75950 | 116 | uLCD.rectangle(52, 48, 76, 56, BLUE); |
soapy12312 | 0:218d3fb75950 | 117 | uLCD.rectangle(60, 80, 68, 104, BLUE); |
soapy12312 | 0:218d3fb75950 | 118 | uLCD.rectangle(52, 80, 76, 88, BLUE); |
soapy12312 | 0:218d3fb75950 | 119 | uLCD.rectangle(60, 81, 68, 88, BLACK); |
soapy12312 | 0:218d3fb75950 | 120 | uLCD.rectangle(60, 48, 68, 55, BLACK); |
soapy12312 | 0:218d3fb75950 | 121 | uLCD.pixel(60, 48, BLUE); |
soapy12312 | 0:218d3fb75950 | 122 | uLCD.pixel(68, 48, BLUE); |
soapy12312 | 0:218d3fb75950 | 123 | uLCD.pixel(60, 88, BLUE); |
soapy12312 | 0:218d3fb75950 | 124 | uLCD.pixel(68, 88, BLUE); |
soapy12312 | 0:218d3fb75950 | 125 | } |
soapy12312 | 0:218d3fb75950 | 126 | |
soapy12312 | 0:218d3fb75950 | 127 | // Set the positions of the players and pac dots |
soapy12312 | 0:218d3fb75950 | 128 | void setPositions() { |
soapy12312 | 0:218d3fb75950 | 129 | // Set the valid positions of the players |
soapy12312 | 0:218d3fb75950 | 130 | for (int i = 0; i < 128; i++) { |
soapy12312 | 0:218d3fb75950 | 131 | for (int j = 0; j < 128; j++) { |
soapy12312 | 0:218d3fb75950 | 132 | positions[i][j] = 0; |
soapy12312 | 0:218d3fb75950 | 133 | } |
soapy12312 | 0:218d3fb75950 | 134 | } |
soapy12312 | 0:218d3fb75950 | 135 | |
soapy12312 | 0:218d3fb75950 | 136 | for (int i = 8; i <= 56; i++) { |
soapy12312 | 0:218d3fb75950 | 137 | positions[i][20] = 1; |
soapy12312 | 0:218d3fb75950 | 138 | positions[i][116] = 1; |
soapy12312 | 0:218d3fb75950 | 139 | } |
soapy12312 | 0:218d3fb75950 | 140 | |
soapy12312 | 0:218d3fb75950 | 141 | for (int j = 20; j <= 36; j++) { |
soapy12312 | 0:218d3fb75950 | 142 | positions[8][j] = 1; |
soapy12312 | 0:218d3fb75950 | 143 | positions[120][j] = 1; |
soapy12312 | 0:218d3fb75950 | 144 | } |
soapy12312 | 0:218d3fb75950 | 145 | |
soapy12312 | 0:218d3fb75950 | 146 | for (int i = 8; i <= 24; i++) { |
soapy12312 | 0:218d3fb75950 | 147 | positions[i][36] = 1; |
soapy12312 | 0:218d3fb75950 | 148 | positions[i][100] = 1; |
soapy12312 | 0:218d3fb75950 | 149 | } |
soapy12312 | 0:218d3fb75950 | 150 | |
soapy12312 | 0:218d3fb75950 | 151 | for (int j = 20; j <= 116; j++) { |
soapy12312 | 0:218d3fb75950 | 152 | positions[24][j] = 1; |
soapy12312 | 0:218d3fb75950 | 153 | positions[104][j] = 1; |
soapy12312 | 0:218d3fb75950 | 154 | } |
soapy12312 | 0:218d3fb75950 | 155 | |
soapy12312 | 0:218d3fb75950 | 156 | for (int j = 20; j <= 44; j++) { |
soapy12312 | 0:218d3fb75950 | 157 | positions[56][j] = 1; |
soapy12312 | 0:218d3fb75950 | 158 | positions[72][j] = 1; |
soapy12312 | 0:218d3fb75950 | 159 | } |
soapy12312 | 0:218d3fb75950 | 160 | |
soapy12312 | 0:218d3fb75950 | 161 | for (int i = 24; i <= 56; i++) { |
soapy12312 | 0:218d3fb75950 | 162 | positions[i][44] = 1; |
soapy12312 | 0:218d3fb75950 | 163 | positions[i][92] = 1; |
soapy12312 | 0:218d3fb75950 | 164 | } |
soapy12312 | 0:218d3fb75950 | 165 | |
soapy12312 | 0:218d3fb75950 | 166 | for (int j = 44; j <= 92; j++) { |
soapy12312 | 0:218d3fb75950 | 167 | positions[48][j] = 1; |
soapy12312 | 0:218d3fb75950 | 168 | positions[80][j] = 1; |
soapy12312 | 0:218d3fb75950 | 169 | } |
soapy12312 | 0:218d3fb75950 | 170 | |
soapy12312 | 0:218d3fb75950 | 171 | for (int i = 4; i <= 48; i++) { |
soapy12312 | 0:218d3fb75950 | 172 | positions[i][68] = 1; |
soapy12312 | 0:218d3fb75950 | 173 | } |
soapy12312 | 0:218d3fb75950 | 174 | |
soapy12312 | 0:218d3fb75950 | 175 | for (int i = 56; i <= 72; i++) { |
soapy12312 | 0:218d3fb75950 | 176 | positions[i][28] = 1; |
soapy12312 | 0:218d3fb75950 | 177 | positions[i][108] = 1; |
soapy12312 | 0:218d3fb75950 | 178 | } |
soapy12312 | 0:218d3fb75950 | 179 | |
soapy12312 | 0:218d3fb75950 | 180 | for (int i = 72; i <= 120; i++) { |
soapy12312 | 0:218d3fb75950 | 181 | positions[i][20] = 1; |
soapy12312 | 0:218d3fb75950 | 182 | positions[i][116] = 1; |
soapy12312 | 0:218d3fb75950 | 183 | } |
soapy12312 | 0:218d3fb75950 | 184 | |
soapy12312 | 0:218d3fb75950 | 185 | for (int i = 72; i <= 104; i++) { |
soapy12312 | 0:218d3fb75950 | 186 | positions[i][44] = 1; |
soapy12312 | 0:218d3fb75950 | 187 | positions[i][92] = 1; |
soapy12312 | 0:218d3fb75950 | 188 | } |
soapy12312 | 0:218d3fb75950 | 189 | |
soapy12312 | 0:218d3fb75950 | 190 | for (int i = 104; i <= 120; i++) { |
soapy12312 | 0:218d3fb75950 | 191 | positions[i][36] = 1; |
soapy12312 | 0:218d3fb75950 | 192 | positions[i][100] = 1; |
soapy12312 | 0:218d3fb75950 | 193 | } |
soapy12312 | 0:218d3fb75950 | 194 | |
soapy12312 | 0:218d3fb75950 | 195 | for (int i = 48; i <= 80; i++) { |
soapy12312 | 0:218d3fb75950 | 196 | positions[i][60] = 1; |
soapy12312 | 0:218d3fb75950 | 197 | positions[i][76] = 1; |
soapy12312 | 0:218d3fb75950 | 198 | } |
soapy12312 | 0:218d3fb75950 | 199 | |
soapy12312 | 0:218d3fb75950 | 200 | for (int i = 80; i <= 124; i++) { |
soapy12312 | 0:218d3fb75950 | 201 | positions[i][68] = 1; |
soapy12312 | 0:218d3fb75950 | 202 | } |
soapy12312 | 0:218d3fb75950 | 203 | |
soapy12312 | 0:218d3fb75950 | 204 | for (int j = 100; j <= 116; j++) { |
soapy12312 | 0:218d3fb75950 | 205 | positions[8][j] = 1; |
soapy12312 | 0:218d3fb75950 | 206 | positions[120][j] = 1; |
soapy12312 | 0:218d3fb75950 | 207 | } |
soapy12312 | 0:218d3fb75950 | 208 | |
soapy12312 | 0:218d3fb75950 | 209 | for (int j = 92; j <= 116; j++) { |
soapy12312 | 0:218d3fb75950 | 210 | positions[56][j] = 1; |
soapy12312 | 0:218d3fb75950 | 211 | positions[72][j] = 1; |
soapy12312 | 0:218d3fb75950 | 212 | } |
soapy12312 | 0:218d3fb75950 | 213 | |
soapy12312 | 0:218d3fb75950 | 214 | // Set valid positions of the pac dots |
soapy12312 | 0:218d3fb75950 | 215 | pacDots = -40; |
soapy12312 | 0:218d3fb75950 | 216 | bigPacDots = 4; |
soapy12312 | 0:218d3fb75950 | 217 | |
soapy12312 | 0:218d3fb75950 | 218 | for (int i = 0; i < 128; i++) { |
soapy12312 | 0:218d3fb75950 | 219 | for (int j = 0; j < 128; j++) { |
soapy12312 | 0:218d3fb75950 | 220 | if (positions[i][j] == 1) { |
soapy12312 | 0:218d3fb75950 | 221 | if ((i % 4 == 0) && (j % 4 == 0)) { |
soapy12312 | 0:218d3fb75950 | 222 | uLCD.pixel(i, j, YELLOW); |
soapy12312 | 0:218d3fb75950 | 223 | pacDots++; |
soapy12312 | 0:218d3fb75950 | 224 | positions[i][j] = 2; |
soapy12312 | 0:218d3fb75950 | 225 | } |
soapy12312 | 0:218d3fb75950 | 226 | } |
soapy12312 | 0:218d3fb75950 | 227 | } |
soapy12312 | 0:218d3fb75950 | 228 | } |
soapy12312 | 0:218d3fb75950 | 229 | |
soapy12312 | 0:218d3fb75950 | 230 | uLCD.rectangle(48, 60, 80, 76, BLACK); |
soapy12312 | 0:218d3fb75950 | 231 | uLCD.line(48, 46, 48, 91, BLACK); |
soapy12312 | 0:218d3fb75950 | 232 | uLCD.line(80, 46, 80, 91, BLACK); |
soapy12312 | 0:218d3fb75950 | 233 | uLCD.line(58, 108, 70, 108, BLACK); |
soapy12312 | 0:218d3fb75950 | 234 | |
soapy12312 | 0:218d3fb75950 | 235 | for (int i = 48; i <= 80; i++) { |
soapy12312 | 0:218d3fb75950 | 236 | for (int j = 45; j < 91; j++) { |
soapy12312 | 0:218d3fb75950 | 237 | if (positions[i][j] == 2) { |
soapy12312 | 0:218d3fb75950 | 238 | positions[i][j] = 1; |
soapy12312 | 0:218d3fb75950 | 239 | } |
soapy12312 | 0:218d3fb75950 | 240 | } |
soapy12312 | 0:218d3fb75950 | 241 | } |
soapy12312 | 0:218d3fb75950 | 242 | |
soapy12312 | 0:218d3fb75950 | 243 | uLCD.filled_circle(8, 100, 1, YELLOW); |
soapy12312 | 0:218d3fb75950 | 244 | positions[8][100] = 3; |
soapy12312 | 0:218d3fb75950 | 245 | uLCD.filled_circle(120, 100, 1, YELLOW); |
soapy12312 | 0:218d3fb75950 | 246 | positions[120][100] = 3; |
soapy12312 | 0:218d3fb75950 | 247 | uLCD.filled_circle(8, 36, 1, YELLOW); |
soapy12312 | 0:218d3fb75950 | 248 | positions[8][36] = 3; |
soapy12312 | 0:218d3fb75950 | 249 | uLCD.filled_circle(120, 36, 1, YELLOW); |
soapy12312 | 0:218d3fb75950 | 250 | positions[120][36] = 3; |
soapy12312 | 0:218d3fb75950 | 251 | } |
soapy12312 | 0:218d3fb75950 | 252 | |
soapy12312 | 0:218d3fb75950 | 253 | // Redraw the current pac dot locations |
soapy12312 | 0:218d3fb75950 | 254 | void redrawPacDots() { |
soapy12312 | 0:218d3fb75950 | 255 | for (int i = 4; i <= 124; i++) { |
soapy12312 | 0:218d3fb75950 | 256 | for (int j = 20; j <= 116; j++) { |
soapy12312 | 0:218d3fb75950 | 257 | if (positions[i][j] == 2) { |
soapy12312 | 0:218d3fb75950 | 258 | uLCD.pixel(i, j, YELLOW); |
soapy12312 | 0:218d3fb75950 | 259 | } else if (positions[i][j] == 3) { |
soapy12312 | 0:218d3fb75950 | 260 | uLCD.filled_circle(i, j, 1, YELLOW); |
soapy12312 | 0:218d3fb75950 | 261 | } |
soapy12312 | 0:218d3fb75950 | 262 | } |
soapy12312 | 0:218d3fb75950 | 263 | } |
soapy12312 | 0:218d3fb75950 | 264 | |
soapy12312 | 0:218d3fb75950 | 265 | uLCD.pixel(64, 108, BLACK); |
soapy12312 | 0:218d3fb75950 | 266 | } |
soapy12312 | 0:218d3fb75950 | 267 | }; |