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