Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 mbed PowerControl
GameScreen.cpp@14:f5760f76fe83, 2015-05-01 (annotated)
- Committer:
- AppleJuice
- Date:
- Fri May 01 16:17:27 2015 +0000
- Revision:
- 14:f5760f76fe83
- Parent:
- 13:7071a14b2fab
- Child:
- 19:97e0516dd6b2
commented all files using Doxygen;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| AppleJuice | 0:c2c1df1163f1 | 1 | #include "mbed.h" |
| AppleJuice | 0:c2c1df1163f1 | 2 | #include "N5110.h" |
| AppleJuice | 0:c2c1df1163f1 | 3 | #include "GameScreen.h" |
| AppleJuice | 0:c2c1df1163f1 | 4 | |
| AppleJuice | 14:f5760f76fe83 | 5 | //initialise function, sets ball pos and creates platforms |
| AppleJuice | 8:ebddb721f1ee | 6 | void GameScreen::Initialize() |
| AppleJuice | 1:3305d7e44880 | 7 | { |
| AppleJuice | 14:f5760f76fe83 | 8 | init(); //power up screen and set brightness |
| AppleJuice | 5:d395a7134278 | 9 | |
| AppleJuice | 14:f5760f76fe83 | 10 | //set ball pos |
| AppleJuice | 14:f5760f76fe83 | 11 | playerBall.x = maxX_/2; |
| AppleJuice | 8:ebddb721f1ee | 12 | playerBall.y = maxY_ - (int)(maxY_/3 * 2) - 5; |
| AppleJuice | 8:ebddb721f1ee | 13 | |
| AppleJuice | 8:ebddb721f1ee | 14 | createAllPlatforms(); |
| AppleJuice | 1:3305d7e44880 | 15 | } |
| AppleJuice | 1:3305d7e44880 | 16 | |
| AppleJuice | 1:3305d7e44880 | 17 | //draw platform |
| AppleJuice | 1:3305d7e44880 | 18 | // ___________ ________ < y |
| AppleJuice | 1:3305d7e44880 | 19 | // ^ x |
| AppleJuice | 1:3305d7e44880 | 20 | void GameScreen::drawPlatform(int x,int y) |
| AppleJuice | 2:d4402bc3dd45 | 21 | { |
| AppleJuice | 1:3305d7e44880 | 22 | for (int a = 0; a < 48; a ++) |
| AppleJuice | 1:3305d7e44880 | 23 | { |
| AppleJuice | 2:d4402bc3dd45 | 24 | for (int b = y; b < (y+platThickness_); b++) |
| AppleJuice | 1:3305d7e44880 | 25 | { |
| AppleJuice | 2:d4402bc3dd45 | 26 | //skip pixels of gap |
| AppleJuice | 2:d4402bc3dd45 | 27 | if (a > x && a < (x + platGapSize_)) |
| AppleJuice | 14:f5760f76fe83 | 28 | break; |
| AppleJuice | 2:d4402bc3dd45 | 29 | |
| AppleJuice | 2:d4402bc3dd45 | 30 | //skip pixels below maxY (lets platforms 'emerge' instead of 'appear') |
| AppleJuice | 2:d4402bc3dd45 | 31 | if (b > (maxY_ - 1)) |
| AppleJuice | 2:d4402bc3dd45 | 32 | break; |
| AppleJuice | 2:d4402bc3dd45 | 33 | |
| AppleJuice | 1:3305d7e44880 | 34 | setPixel(b,a); |
| AppleJuice | 1:3305d7e44880 | 35 | } |
| AppleJuice | 1:3305d7e44880 | 36 | } |
| AppleJuice | 2:d4402bc3dd45 | 37 | } |
| AppleJuice | 2:d4402bc3dd45 | 38 | |
| AppleJuice | 2:d4402bc3dd45 | 39 | //erase platform |
| AppleJuice | 2:d4402bc3dd45 | 40 | void GameScreen::erasePlatform(int y) |
| AppleJuice | 2:d4402bc3dd45 | 41 | { |
| AppleJuice | 2:d4402bc3dd45 | 42 | for (int a = 0; a < 48; a ++) |
| AppleJuice | 2:d4402bc3dd45 | 43 | { |
| AppleJuice | 2:d4402bc3dd45 | 44 | for (int b = y; b < (y+platThickness_); b++) |
| AppleJuice | 2:d4402bc3dd45 | 45 | { |
| AppleJuice | 2:d4402bc3dd45 | 46 | //skip pixels below maxY (lets platforms 'emerge' instead of 'appear') |
| AppleJuice | 2:d4402bc3dd45 | 47 | if (b > (maxY_ - 1)) |
| AppleJuice | 2:d4402bc3dd45 | 48 | break; |
| AppleJuice | 2:d4402bc3dd45 | 49 | |
| AppleJuice | 2:d4402bc3dd45 | 50 | clearPixel(b,a); |
| AppleJuice | 2:d4402bc3dd45 | 51 | } |
| AppleJuice | 2:d4402bc3dd45 | 52 | } |
| AppleJuice | 2:d4402bc3dd45 | 53 | } |
| AppleJuice | 2:d4402bc3dd45 | 54 | |
| AppleJuice | 2:d4402bc3dd45 | 55 | //draw the player ball where (x,y) is top right corner. |
| AppleJuice | 2:d4402bc3dd45 | 56 | // XXP <-- P(x,y) |
| AppleJuice | 2:d4402bc3dd45 | 57 | // XXXX |
| AppleJuice | 2:d4402bc3dd45 | 58 | // XXXX |
| AppleJuice | 2:d4402bc3dd45 | 59 | // XX |
| AppleJuice | 5:d395a7134278 | 60 | void GameScreen::drawBall() |
| AppleJuice | 2:d4402bc3dd45 | 61 | { |
| AppleJuice | 2:d4402bc3dd45 | 62 | //more elegant ways to do this...but this is most efficient |
| AppleJuice | 5:d395a7134278 | 63 | setPixel(playerBall.y,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 64 | setPixel(playerBall.y,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 65 | setPixel(playerBall.y+1,playerBall.x); |
| AppleJuice | 5:d395a7134278 | 66 | setPixel(playerBall.y+1,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 67 | setPixel(playerBall.y+1,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 68 | setPixel(playerBall.y+1,playerBall.x+3); |
| AppleJuice | 5:d395a7134278 | 69 | setPixel(playerBall.y+2,playerBall.x); |
| AppleJuice | 5:d395a7134278 | 70 | setPixel(playerBall.y+2,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 71 | setPixel(playerBall.y+2,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 72 | setPixel(playerBall.y+2,playerBall.x+3); |
| AppleJuice | 5:d395a7134278 | 73 | setPixel(playerBall.y+3,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 74 | setPixel(playerBall.y+3,playerBall.x+2); |
| AppleJuice | 2:d4402bc3dd45 | 75 | } |
| AppleJuice | 2:d4402bc3dd45 | 76 | |
| AppleJuice | 2:d4402bc3dd45 | 77 | //draw the player ball where (x,y) is top right corner. |
| AppleJuice | 5:d395a7134278 | 78 | void GameScreen::eraseBall() |
| AppleJuice | 2:d4402bc3dd45 | 79 | { |
| AppleJuice | 5:d395a7134278 | 80 | clearPixel(playerBall.y,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 81 | clearPixel(playerBall.y,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 82 | clearPixel(playerBall.y+1,playerBall.x); |
| AppleJuice | 5:d395a7134278 | 83 | clearPixel(playerBall.y+1,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 84 | clearPixel(playerBall.y+1,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 85 | clearPixel(playerBall.y+1,playerBall.x+3); |
| AppleJuice | 5:d395a7134278 | 86 | clearPixel(playerBall.y+2,playerBall.x); |
| AppleJuice | 5:d395a7134278 | 87 | clearPixel(playerBall.y+2,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 88 | clearPixel(playerBall.y+2,playerBall.x+2); |
| AppleJuice | 5:d395a7134278 | 89 | clearPixel(playerBall.y+2,playerBall.x+3); |
| AppleJuice | 5:d395a7134278 | 90 | clearPixel(playerBall.y+3,playerBall.x+1); |
| AppleJuice | 5:d395a7134278 | 91 | clearPixel(playerBall.y+3,playerBall.x+2); |
| AppleJuice | 2:d4402bc3dd45 | 92 | } |
| AppleJuice | 2:d4402bc3dd45 | 93 | |
| AppleJuice | 2:d4402bc3dd45 | 94 | void GameScreen::createAllPlatforms() |
| AppleJuice | 2:d4402bc3dd45 | 95 | { |
| AppleJuice | 2:d4402bc3dd45 | 96 | for (int n = 0; n < numPlatforms_ ; n++) |
| AppleJuice | 2:d4402bc3dd45 | 97 | { |
| AppleJuice | 14:f5760f76fe83 | 98 | //create new platform and add to allPlatform array. |
| AppleJuice | 14:f5760f76fe83 | 99 | Platform *newPlatform = new Platform; |
| AppleJuice | 14:f5760f76fe83 | 100 | newPlatform->id = n; |
| AppleJuice | 14:f5760f76fe83 | 101 | newPlatform->x = rand() % (maxX_-platGapSize_ + 1) - 1; //randomlly select platform location |
| AppleJuice | 2:d4402bc3dd45 | 102 | newPlatform->y = maxY_ - n*platSpacing_ - platThickness_ + 1; |
| AppleJuice | 2:d4402bc3dd45 | 103 | allPlatforms[n] = newPlatform; |
| AppleJuice | 2:d4402bc3dd45 | 104 | } |
| AppleJuice | 2:d4402bc3dd45 | 105 | } |
| AppleJuice | 2:d4402bc3dd45 | 106 | |
| AppleJuice | 14:f5760f76fe83 | 107 | //Garbage cleanup, free all the platforms! |
| AppleJuice | 2:d4402bc3dd45 | 108 | void GameScreen::freeAllPlatforms() |
| AppleJuice | 2:d4402bc3dd45 | 109 | { |
| AppleJuice | 2:d4402bc3dd45 | 110 | for (int n = 0; n < numPlatforms_ ; n++) |
| AppleJuice | 2:d4402bc3dd45 | 111 | { |
| AppleJuice | 2:d4402bc3dd45 | 112 | delete allPlatforms[n]; |
| AppleJuice | 2:d4402bc3dd45 | 113 | } |
| AppleJuice | 2:d4402bc3dd45 | 114 | } |
| AppleJuice | 2:d4402bc3dd45 | 115 | |
| AppleJuice | 2:d4402bc3dd45 | 116 | void GameScreen::drawAllPlatforms() |
| AppleJuice | 2:d4402bc3dd45 | 117 | { |
| AppleJuice | 2:d4402bc3dd45 | 118 | for (int n = 0; n < numPlatforms_ ; n++) |
| AppleJuice | 2:d4402bc3dd45 | 119 | { |
| AppleJuice | 2:d4402bc3dd45 | 120 | drawPlatform (allPlatforms[n]->x,allPlatforms[n]->y); |
| AppleJuice | 2:d4402bc3dd45 | 121 | } |
| AppleJuice | 2:d4402bc3dd45 | 122 | } |
| AppleJuice | 2:d4402bc3dd45 | 123 | |
| AppleJuice | 2:d4402bc3dd45 | 124 | void GameScreen::eraseAllPlatforms() |
| AppleJuice | 2:d4402bc3dd45 | 125 | { |
| AppleJuice | 2:d4402bc3dd45 | 126 | for (int n = 0; n < numPlatforms_ ; n++) |
| AppleJuice | 2:d4402bc3dd45 | 127 | { |
| AppleJuice | 2:d4402bc3dd45 | 128 | erasePlatform (allPlatforms[n]->y); |
| AppleJuice | 2:d4402bc3dd45 | 129 | } |
| AppleJuice | 2:d4402bc3dd45 | 130 | } |
| AppleJuice | 2:d4402bc3dd45 | 131 | |
| AppleJuice | 14:f5760f76fe83 | 132 | void GameScreen::shiftAllPlatforms(int n ) |
| AppleJuice | 2:d4402bc3dd45 | 133 | { |
| AppleJuice | 14:f5760f76fe83 | 134 | for (int i = 0; i < numPlatforms_ ; i++) |
| AppleJuice | 2:d4402bc3dd45 | 135 | { |
| AppleJuice | 14:f5760f76fe83 | 136 | if (allPlatforms[i]->y > (platThickness_+5+n)) |
| AppleJuice | 14:f5760f76fe83 | 137 | allPlatforms[i]->y = allPlatforms[i]->y - n; |
| AppleJuice | 2:d4402bc3dd45 | 138 | else |
| AppleJuice | 3:00c0f63f4408 | 139 | { |
| AppleJuice | 14:f5760f76fe83 | 140 | allPlatforms[i]->y = maxY_ - platThickness_ + 1+6; //send back to bottom. |
| AppleJuice | 14:f5760f76fe83 | 141 | allPlatforms[i]->x = rand() % (maxX_-platGapSize_ + 1) - 1; //select a new random position of gap! |
| AppleJuice | 5:d395a7134278 | 142 | |
| AppleJuice | 3:00c0f63f4408 | 143 | } |
| AppleJuice | 2:d4402bc3dd45 | 144 | } |
| AppleJuice | 4:f8d04c073730 | 145 | } |
| AppleJuice | 4:f8d04c073730 | 146 | |
| AppleJuice | 5:d395a7134278 | 147 | Platform GameScreen::nextClosestPlatform(int y) |
| AppleJuice | 5:d395a7134278 | 148 | { |
| AppleJuice | 10:d8ef8633bd98 | 149 | int closestY = 100; |
| AppleJuice | 5:d395a7134278 | 150 | Platform closestPlatform; |
| AppleJuice | 14:f5760f76fe83 | 151 | //scan each platform and determin which is closest. |
| AppleJuice | 5:d395a7134278 | 152 | for (int i = 0; i < numPlatforms_; i++) |
| AppleJuice | 5:d395a7134278 | 153 | { |
| AppleJuice | 10:d8ef8633bd98 | 154 | |
| AppleJuice | 10:d8ef8633bd98 | 155 | if (((allPlatforms[i]->y - y) < closestY) && ((allPlatforms[i]->y - y) > -1)) |
| AppleJuice | 5:d395a7134278 | 156 | { |
| AppleJuice | 10:d8ef8633bd98 | 157 | closestY = allPlatforms[i]->y-y; |
| AppleJuice | 5:d395a7134278 | 158 | closestPlatform = *allPlatforms[i]; |
| AppleJuice | 5:d395a7134278 | 159 | } |
| AppleJuice | 5:d395a7134278 | 160 | } |
| AppleJuice | 5:d395a7134278 | 161 | return closestPlatform; |
| AppleJuice | 5:d395a7134278 | 162 | } |
| AppleJuice | 4:f8d04c073730 | 163 | |
| AppleJuice | 6:b1c54f8b28fe | 164 | //@Override of base class function |
| AppleJuice | 6:b1c54f8b28fe | 165 | //had to override and rewrite since N5110 is written to write horizontal this needs vertical |
| AppleJuice | 6:b1c54f8b28fe | 166 | // this function reads existing font5x7 and rotate matrix to become font7x5 matrix. |
| AppleJuice | 6:b1c54f8b28fe | 167 | // |
| AppleJuice | 6:b1c54f8b28fe | 168 | // for example the number 4 font5x7 = 0x18,0x14,0x12,0x7F,0x10 |
| AppleJuice | 6:b1c54f8b28fe | 169 | // font7x5 = 0x02,0x06,0x10,0x12,0x1E,0x2,0x2 |
| AppleJuice | 6:b1c54f8b28fe | 170 | //then it is printed! |
| AppleJuice | 11:c6c88617f7e7 | 171 | void GameScreen::printString(const char * str,int x,int y,bool invert) |
| AppleJuice | 6:b1c54f8b28fe | 172 | { |
| AppleJuice | 12:9ba4b21f8220 | 173 | //set all pixels in rows to black |
| AppleJuice | 11:c6c88617f7e7 | 174 | if (invert){ |
| AppleJuice | 11:c6c88617f7e7 | 175 | for (int a = 0; a < 48; a ++) |
| AppleJuice | 11:c6c88617f7e7 | 176 | { |
| AppleJuice | 11:c6c88617f7e7 | 177 | for (int b = y; b < (y+9); b++) |
| AppleJuice | 11:c6c88617f7e7 | 178 | { |
| AppleJuice | 11:c6c88617f7e7 | 179 | setPixel(b,a); |
| AppleJuice | 11:c6c88617f7e7 | 180 | } |
| AppleJuice | 11:c6c88617f7e7 | 181 | } |
| AppleJuice | 11:c6c88617f7e7 | 182 | } |
| AppleJuice | 11:c6c88617f7e7 | 183 | |
| AppleJuice | 14:f5760f76fe83 | 184 | //scan through string, rotating font5x7 array and printing charector. |
| AppleJuice | 6:b1c54f8b28fe | 185 | while (*str) |
| AppleJuice | 6:b1c54f8b28fe | 186 | { |
| AppleJuice | 11:c6c88617f7e7 | 187 | |
| AppleJuice | 6:b1c54f8b28fe | 188 | //each byte in row |
| AppleJuice | 6:b1c54f8b28fe | 189 | for (int i = 0; i < 5; i++) |
| AppleJuice | 6:b1c54f8b28fe | 190 | { |
| AppleJuice | 6:b1c54f8b28fe | 191 | //each bit in byte |
| AppleJuice | 8:ebddb721f1ee | 192 | for (int b = 0; b < 7; b++) |
| AppleJuice | 11:c6c88617f7e7 | 193 | { |
| AppleJuice | 11:c6c88617f7e7 | 194 | if (invert) |
| AppleJuice | 11:c6c88617f7e7 | 195 | setPixel(y+b+1,x-i+1); |
| AppleJuice | 11:c6c88617f7e7 | 196 | |
| AppleJuice | 8:ebddb721f1ee | 197 | if (font5x7[(*str - 32)*5 + i] & (1<<b)) //bitwise comparison to mask at desired pixel |
| AppleJuice | 8:ebddb721f1ee | 198 | { |
| AppleJuice | 11:c6c88617f7e7 | 199 | setPixel(y+b+1,x-i+1); |
| AppleJuice | 11:c6c88617f7e7 | 200 | if (invert) |
| AppleJuice | 11:c6c88617f7e7 | 201 | clearPixel(y+b+1,x-i+1); |
| AppleJuice | 6:b1c54f8b28fe | 202 | } |
| AppleJuice | 6:b1c54f8b28fe | 203 | else |
| AppleJuice | 8:ebddb721f1ee | 204 | { |
| AppleJuice | 11:c6c88617f7e7 | 205 | if (!invert) |
| AppleJuice | 11:c6c88617f7e7 | 206 | clearPixel(y+b+1,x-i+1); |
| AppleJuice | 8:ebddb721f1ee | 207 | } |
| AppleJuice | 6:b1c54f8b28fe | 208 | } |
| AppleJuice | 8:ebddb721f1ee | 209 | } |
| AppleJuice | 14:f5760f76fe83 | 210 | str ++; //next char in string |
| AppleJuice | 8:ebddb721f1ee | 211 | x -= 6; |
| AppleJuice | 14:f5760f76fe83 | 212 | } |
| AppleJuice | 8:ebddb721f1ee | 213 | } |
| AppleJuice | 8:ebddb721f1ee | 214 | |
| AppleJuice | 8:ebddb721f1ee | 215 | void GameScreen::displayStartScreen() |
| AppleJuice | 8:ebddb721f1ee | 216 | { |
| AppleJuice | 8:ebddb721f1ee | 217 | clear(); |
| AppleJuice | 8:ebddb721f1ee | 218 | printString("LET",maxX_ - 14,-1); |
| AppleJuice | 8:ebddb721f1ee | 219 | printString("THE BALL",maxX_ - 2,7); |
| AppleJuice | 8:ebddb721f1ee | 220 | printString("DROP!",maxX_ - 12,16); |
| AppleJuice | 8:ebddb721f1ee | 221 | printString("This way",maxX_ - 2,30); |
| AppleJuice | 8:ebddb721f1ee | 222 | printString("------->",maxX_ - 2,37); |
| AppleJuice | 8:ebddb721f1ee | 223 | printString("TO PLAY!",maxX_ - 2,45); |
| AppleJuice | 8:ebddb721f1ee | 224 | printString("by: ",maxX_ - 2,61); |
| AppleJuice | 8:ebddb721f1ee | 225 | printString("Thomas",maxX_ - 9,69); |
| AppleJuice | 8:ebddb721f1ee | 226 | printString("Davies",maxX_ - 9,76); |
| AppleJuice | 8:ebddb721f1ee | 227 | refresh(); |
| AppleJuice | 8:ebddb721f1ee | 228 | } |
| AppleJuice | 8:ebddb721f1ee | 229 | |
| AppleJuice | 8:ebddb721f1ee | 230 | void GameScreen::displayInstructionScreen() |
| AppleJuice | 8:ebddb721f1ee | 231 | { |
| AppleJuice | 8:ebddb721f1ee | 232 | clear(); |
| AppleJuice | 8:ebddb721f1ee | 233 | printString("Hi Ball,",maxX_ - 2,-1); |
| AppleJuice | 8:ebddb721f1ee | 234 | printString("You are",maxX_ - 2,7); |
| AppleJuice | 8:ebddb721f1ee | 235 | printString("TRAPPED!",maxX_ - 2,15); |
| AppleJuice | 8:ebddb721f1ee | 236 | printString("Use the ",maxX_ - 2,23); |
| AppleJuice | 8:ebddb721f1ee | 237 | printString("joystick",maxX_ - 2,32); |
| AppleJuice | 8:ebddb721f1ee | 238 | printString("to move.",maxX_ - 2,39); |
| AppleJuice | 8:ebddb721f1ee | 239 | printString("Don't",maxX_ - 2,47); |
| AppleJuice | 8:ebddb721f1ee | 240 | printString("hit the",maxX_ - 2,55); |
| AppleJuice | 8:ebddb721f1ee | 241 | printString("roof!",maxX_ - 2,63); |
| AppleJuice | 8:ebddb721f1ee | 242 | printString("------->",maxX_ - 2,75); |
| AppleJuice | 8:ebddb721f1ee | 243 | refresh(); |
| AppleJuice | 8:ebddb721f1ee | 244 | } |
| AppleJuice | 8:ebddb721f1ee | 245 | |
| AppleJuice | 8:ebddb721f1ee | 246 | void GameScreen::displayCountdown() |
| AppleJuice | 8:ebddb721f1ee | 247 | { |
| AppleJuice | 8:ebddb721f1ee | 248 | clear(); |
| AppleJuice | 14:f5760f76fe83 | 249 | Timer countdown; //timer for countdown |
| AppleJuice | 8:ebddb721f1ee | 250 | char buffer[10]; |
| AppleJuice | 8:ebddb721f1ee | 251 | countdown.start(); |
| AppleJuice | 14:f5760f76fe83 | 252 | printString("Survive!",maxX_ - 2,10); |
| AppleJuice | 14:f5760f76fe83 | 253 | refresh(); |
| AppleJuice | 8:ebddb721f1ee | 254 | |
| AppleJuice | 8:ebddb721f1ee | 255 | int prevTime = -1; |
| AppleJuice | 14:f5760f76fe83 | 256 | //countdown from 5 to 1, in seconds. |
| AppleJuice | 8:ebddb721f1ee | 257 | while (countdown.read() < 5) |
| AppleJuice | 8:ebddb721f1ee | 258 | { |
| AppleJuice | 8:ebddb721f1ee | 259 | if (floor(countdown.read()) > prevTime) |
| AppleJuice | 8:ebddb721f1ee | 260 | { |
| AppleJuice | 8:ebddb721f1ee | 261 | sprintf(buffer,"..%1.0f..",(5 - floor(countdown.read()))); |
| AppleJuice | 8:ebddb721f1ee | 262 | printString(buffer,maxX_ - 10,20 + 10*countdown.read()); |
| AppleJuice | 14:f5760f76fe83 | 263 | refresh(); |
| AppleJuice | 8:ebddb721f1ee | 264 | prevTime = countdown.read(); |
| AppleJuice | 6:b1c54f8b28fe | 265 | } |
| AppleJuice | 6:b1c54f8b28fe | 266 | } |
| AppleJuice | 8:ebddb721f1ee | 267 | countdown.stop(); |
| AppleJuice | 6:b1c54f8b28fe | 268 | } |
| AppleJuice | 5:d395a7134278 | 269 | |
| AppleJuice | 14:f5760f76fe83 | 270 | void GameScreen::displayEndScreen(int lvl,int *cursor, bool isRecord) |
| AppleJuice | 11:c6c88617f7e7 | 271 | { |
| AppleJuice | 11:c6c88617f7e7 | 272 | clear(); |
| AppleJuice | 11:c6c88617f7e7 | 273 | char buffer [10]; |
| AppleJuice | 11:c6c88617f7e7 | 274 | sprintf(buffer,"lvl: %d",lvl); |
| AppleJuice | 11:c6c88617f7e7 | 275 | printString("GameOver",maxX_ - 2,-1); |
| AppleJuice | 11:c6c88617f7e7 | 276 | printString(" :( ",maxX_ - 2,7); |
| AppleJuice | 11:c6c88617f7e7 | 277 | printString(buffer,maxX_ - 2,23); |
| AppleJuice | 11:c6c88617f7e7 | 278 | printString("Reached!",maxX_ - 2,32); |
| AppleJuice | 5:d395a7134278 | 279 | |
| AppleJuice | 14:f5760f76fe83 | 280 | //only display record option if player achieved record! |
| AppleJuice | 14:f5760f76fe83 | 281 | if (isRecord) |
| AppleJuice | 14:f5760f76fe83 | 282 | printString("Record",maxX_ - 8,55,cursor[0]); |
| AppleJuice | 14:f5760f76fe83 | 283 | |
| AppleJuice | 11:c6c88617f7e7 | 284 | printString("View",maxX_ - 15,63,cursor[1]); |
| AppleJuice | 12:9ba4b21f8220 | 285 | printString("Restart",maxX_ - 5,71,cursor[2]); |
| AppleJuice | 11:c6c88617f7e7 | 286 | refresh(); |
| AppleJuice | 11:c6c88617f7e7 | 287 | } |
| AppleJuice | 11:c6c88617f7e7 | 288 | |
| AppleJuice | 12:9ba4b21f8220 | 289 | void GameScreen::displayRecordScreen(int *cursor,char ltr1,char ltr2,char ltr3) |
| AppleJuice | 12:9ba4b21f8220 | 290 | { |
| AppleJuice | 12:9ba4b21f8220 | 291 | clear(); |
| AppleJuice | 12:9ba4b21f8220 | 292 | printString("Enter",maxX_ - 2,-1); |
| AppleJuice | 12:9ba4b21f8220 | 293 | printString("Initials",maxX_ - 2,7); |
| AppleJuice | 12:9ba4b21f8220 | 294 | |
| AppleJuice | 12:9ba4b21f8220 | 295 | //letter entry |
| AppleJuice | 12:9ba4b21f8220 | 296 | char buffer[2]; |
| AppleJuice | 12:9ba4b21f8220 | 297 | sprintf(buffer,"%c",ltr1); |
| AppleJuice | 12:9ba4b21f8220 | 298 | printString(buffer,maxX_ - 23,20,cursor[0]); |
| AppleJuice | 12:9ba4b21f8220 | 299 | sprintf(buffer,"%c",ltr2); |
| AppleJuice | 12:9ba4b21f8220 | 300 | printString(buffer,maxX_ - 23,32,cursor[1]); |
| AppleJuice | 12:9ba4b21f8220 | 301 | sprintf(buffer,"%c",ltr3); |
| AppleJuice | 12:9ba4b21f8220 | 302 | printString(buffer,maxX_ - 23,44,cursor[2]); |
| AppleJuice | 12:9ba4b21f8220 | 303 | |
| AppleJuice | 12:9ba4b21f8220 | 304 | printString("Click",maxX_ - 2,59); |
| AppleJuice | 12:9ba4b21f8220 | 305 | printString("when",maxX_ - 2,67); |
| AppleJuice | 12:9ba4b21f8220 | 306 | printString("finished",maxX_ - 2,75); |
| AppleJuice | 12:9ba4b21f8220 | 307 | refresh(); |
| AppleJuice | 12:9ba4b21f8220 | 308 | |
| AppleJuice | 12:9ba4b21f8220 | 309 | } |
| AppleJuice | 12:9ba4b21f8220 | 310 | |
| AppleJuice | 14:f5760f76fe83 | 311 | void GameScreen::displayHighScores(char *s_hs0,char *s_hs1,char *s_hs2,int *d_hs) |
| AppleJuice | 13:7071a14b2fab | 312 | { |
| AppleJuice | 13:7071a14b2fab | 313 | clear(); |
| AppleJuice | 13:7071a14b2fab | 314 | printString("SCORES",maxX_ - 2,-1); |
| AppleJuice | 13:7071a14b2fab | 315 | |
| AppleJuice | 13:7071a14b2fab | 316 | char buffer[10]; |
| AppleJuice | 13:7071a14b2fab | 317 | |
| AppleJuice | 14:f5760f76fe83 | 318 | sprintf(buffer,"1.%s %d",s_hs0,d_hs[0]); |
| AppleJuice | 13:7071a14b2fab | 319 | printString(buffer,maxX_ - 2,15); |
| AppleJuice | 13:7071a14b2fab | 320 | |
| AppleJuice | 14:f5760f76fe83 | 321 | sprintf(buffer,"2.%s %d",s_hs1,d_hs[1]); |
| AppleJuice | 13:7071a14b2fab | 322 | printString(buffer,maxX_ - 2,33); |
| AppleJuice | 13:7071a14b2fab | 323 | |
| AppleJuice | 14:f5760f76fe83 | 324 | sprintf(buffer,"3.%s %d",s_hs2,d_hs[2]); |
| AppleJuice | 14:f5760f76fe83 | 325 | printString(buffer,maxX_ - 2,51); |
| AppleJuice | 13:7071a14b2fab | 326 | |
| AppleJuice | 14:f5760f76fe83 | 327 | printString("Click to",maxX_ - 2,68); |
| AppleJuice | 14:f5760f76fe83 | 328 | printString("reset!",maxX_ - 2,76); |
| AppleJuice | 14:f5760f76fe83 | 329 | refresh(); |
| AppleJuice | 13:7071a14b2fab | 330 | } |
| AppleJuice | 13:7071a14b2fab | 331 |