Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen

Dependencies:   N5110 PowerControl mbed

Committer:
ThomasBGill
Date:
Mon May 11 22:29:04 2015 +0000
Revision:
37:a0ea57af9279
Parent:
35:2c290fa78f1d
Fixed error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasBGill 26:0dd71fc0ede4 1 #include "Game.h"
ThomasBGill 23:1b8b1d043403 2
ThomasBGill 35:2c290fa78f1d 3 int main()
ThomasBGill 35:2c290fa78f1d 4 {
ThomasBGill 35:2c290fa78f1d 5 calibrateJoystick(); // get centred values of joystick
ThomasBGill 35:2c290fa78f1d 6 pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 10 times per second
ThomasBGill 35:2c290fa78f1d 7
ThomasBGill 35:2c290fa78f1d 8 //Power Saving
ThomasBGill 35:2c290fa78f1d 9 PHY_PowerDown();
ThomasBGill 35:2c290fa78f1d 10 int result = semihost_powerdown();
ThomasBGill 35:2c290fa78f1d 11
ThomasBGill 35:2c290fa78f1d 12 //Initilize switches
ThomasBGill 35:2c290fa78f1d 13 Start.mode(PullDown);
ThomasBGill 35:2c290fa78f1d 14 Act.mode(PullDown);
ThomasBGill 35:2c290fa78f1d 15 Start.fall(&StartPressed);
ThomasBGill 35:2c290fa78f1d 16 Act.fall(&ActPressed);
ThomasBGill 35:2c290fa78f1d 17
ThomasBGill 35:2c290fa78f1d 18 //Generate random seed
ThomasBGill 35:2c290fa78f1d 19 srand(Noise * 1000000);
ThomasBGill 35:2c290fa78f1d 20
ThomasBGill 35:2c290fa78f1d 21 //Initilize screen
ThomasBGill 35:2c290fa78f1d 22 lcd.init();
ThomasBGill 35:2c290fa78f1d 23
ThomasBGill 35:2c290fa78f1d 24 //Display game title screen
ThomasBGill 35:2c290fa78f1d 25 Intro();
ThomasBGill 35:2c290fa78f1d 26
ThomasBGill 35:2c290fa78f1d 27 //Start game
ThomasBGill 35:2c290fa78f1d 28 MainMenu();
ThomasBGill 35:2c290fa78f1d 29 }
ThomasBGill 35:2c290fa78f1d 30
ThomasBGill 1:0f774d41584c 31 //Power Saving
ThomasBGill 1:0f774d41584c 32 int semihost_powerdown()
ThomasBGill 1:0f774d41584c 33 {
ThomasBGill 1:0f774d41584c 34 uint32_t arg;
ThomasBGill 1:0f774d41584c 35 return __semihost(USR_POWERDOWN, &arg);
ThomasBGill 1:0f774d41584c 36 }
ThomasBGill 1:0f774d41584c 37
ThomasBGill 0:9200b3c387ed 38 //ISR
ThomasBGill 0:9200b3c387ed 39 void ActPressed()
ThomasBGill 0:9200b3c387ed 40 {
ThomasBGill 9:3cad581b5419 41 ActFlag = 1;
ThomasBGill 0:9200b3c387ed 42 }
ThomasBGill 0:9200b3c387ed 43 void StartPressed()
ThomasBGill 0:9200b3c387ed 44 {
ThomasBGill 9:3cad581b5419 45 StartFlag = 1;
ThomasBGill 0:9200b3c387ed 46 }
ThomasBGill 10:59c874d006ab 47
ThomasBGill 31:5b4a4d225ab4 48 //Joystick functions
ThomasBGill 31:5b4a4d225ab4 49 // read default positions of the joystick to calibrate later readings
ThomasBGill 31:5b4a4d225ab4 50 void calibrateJoystick()
ThomasBGill 31:5b4a4d225ab4 51 {
ThomasBGill 31:5b4a4d225ab4 52 //button.mode(PullDown);
ThomasBGill 31:5b4a4d225ab4 53 // must not move during calibration
ThomasBGill 31:5b4a4d225ab4 54 joystick.x0 = xPot; // initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
ThomasBGill 31:5b4a4d225ab4 55 joystick.y0 = yPot;
ThomasBGill 31:5b4a4d225ab4 56 }
ThomasBGill 31:5b4a4d225ab4 57 void updateJoystick()
ThomasBGill 31:5b4a4d225ab4 58 {
ThomasBGill 31:5b4a4d225ab4 59 // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
ThomasBGill 31:5b4a4d225ab4 60 joystick.x = xPot - joystick.x0;
ThomasBGill 31:5b4a4d225ab4 61 joystick.y = yPot - joystick.y0;
ThomasBGill 31:5b4a4d225ab4 62 // read button state
ThomasBGill 31:5b4a4d225ab4 63
ThomasBGill 31:5b4a4d225ab4 64 // calculate direction depending on x,y values
ThomasBGill 31:5b4a4d225ab4 65 // tolerance allows a little lee-way in case joystick not exactly in the stated direction
ThomasBGill 31:5b4a4d225ab4 66 if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
ThomasBGill 31:5b4a4d225ab4 67 joystick.direction = Centre;
ThomasBGill 31:5b4a4d225ab4 68 } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
ThomasBGill 32:99ca304085e6 69 joystick.direction = Down;
ThomasBGill 31:5b4a4d225ab4 70 } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
ThomasBGill 32:99ca304085e6 71 joystick.direction = Up;
ThomasBGill 31:5b4a4d225ab4 72 } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
ThomasBGill 31:5b4a4d225ab4 73 joystick.direction = Right;
ThomasBGill 31:5b4a4d225ab4 74 } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
ThomasBGill 31:5b4a4d225ab4 75 joystick.direction = Left;
ThomasBGill 31:5b4a4d225ab4 76 } else {
ThomasBGill 31:5b4a4d225ab4 77 joystick.direction = Unknown;
ThomasBGill 31:5b4a4d225ab4 78 }
ThomasBGill 31:5b4a4d225ab4 79 }
ThomasBGill 26:0dd71fc0ede4 80
ThomasBGill 22:dae750e4d749 81
ThomasBGill 23:1b8b1d043403 82 //High score system
ThomasBGill 23:1b8b1d043403 83 void writeDataToFile()
ThomasBGill 23:1b8b1d043403 84 {
ThomasBGill 23:1b8b1d043403 85 FILE *fp = fopen("/local/highscore.txt", "w"); // open 'highscore.txt' for writing
ThomasBGill 23:1b8b1d043403 86 fprintf(fp,"%d\r\n",HScore1); // print score to file
ThomasBGill 23:1b8b1d043403 87 fprintf(fp,"%d\r\n",HScore2); // print score to file
ThomasBGill 23:1b8b1d043403 88 fprintf(fp,"%d\r\n",HScore3); // print score to file
ThomasBGill 24:4c4467971c91 89 fprintf(fp,"%d\r\n",HScore4); // print score to file
ThomasBGill 23:1b8b1d043403 90 fclose(fp); // close file
ThomasBGill 23:1b8b1d043403 91 }
ThomasBGill 23:1b8b1d043403 92
ThomasBGill 23:1b8b1d043403 93 void readDataFromFile()
ThomasBGill 23:1b8b1d043403 94 {
ThomasBGill 24:4c4467971c91 95 FILE *fp = fopen("/local/highscore.txt", "r"); // open 'highscore.txt' for writing
ThomasBGill 23:1b8b1d043403 96 fscanf(fp,"%d", &HScore1); // read score from file and save to int
ThomasBGill 23:1b8b1d043403 97 fscanf(fp,"%d", &HScore2); // read score from file and save to int
ThomasBGill 23:1b8b1d043403 98 fscanf(fp,"%d", &HScore3); // read score from file and save to int
ThomasBGill 24:4c4467971c91 99 fscanf(fp,"%d", &HScore4); // read score from file and save to int
ThomasBGill 23:1b8b1d043403 100 fclose(fp); // close file
ThomasBGill 23:1b8b1d043403 101 }
ThomasBGill 23:1b8b1d043403 102
ThomasBGill 23:1b8b1d043403 103 void HighScoreCheck()
ThomasBGill 23:1b8b1d043403 104 {
ThomasBGill 23:1b8b1d043403 105 readDataFromFile();
ThomasBGill 23:1b8b1d043403 106
ThomasBGill 23:1b8b1d043403 107 if(score >= HScore1) {
ThomasBGill 24:4c4467971c91 108 HScore4 = HScore3;
ThomasBGill 23:1b8b1d043403 109 HScore3 = HScore2;
ThomasBGill 23:1b8b1d043403 110 HScore2 = HScore1;
ThomasBGill 23:1b8b1d043403 111 HScore1 = score;
ThomasBGill 23:1b8b1d043403 112 } else if(score >= HScore2) {
ThomasBGill 24:4c4467971c91 113 HScore4 = HScore3;
ThomasBGill 23:1b8b1d043403 114 HScore3 = HScore2;
ThomasBGill 23:1b8b1d043403 115 HScore2 = score;
ThomasBGill 24:4c4467971c91 116 } else if(score >= HScore3) {
ThomasBGill 24:4c4467971c91 117 HScore4 = HScore3;
ThomasBGill 23:1b8b1d043403 118 HScore3 = score;
ThomasBGill 24:4c4467971c91 119 } else if(score > HScore4) {
ThomasBGill 24:4c4467971c91 120 HScore4 = score;
ThomasBGill 23:1b8b1d043403 121 }
ThomasBGill 23:1b8b1d043403 122
ThomasBGill 23:1b8b1d043403 123 writeDataToFile();
ThomasBGill 23:1b8b1d043403 124 }
ThomasBGill 23:1b8b1d043403 125
ThomasBGill 28:b3a597b38b60 126 //Graphic functions
ThomasBGill 28:b3a597b38b60 127 void DrawGraphic(int p, int y, int x)
ThomasBGill 22:dae750e4d749 128 {
ThomasBGill 28:b3a597b38b60 129
ThomasBGill 28:b3a597b38b60 130 for(int i = 0; i < 38; i++) {
ThomasBGill 28:b3a597b38b60 131 for(int j = 0; j < 38; j++) {
ThomasBGill 22:dae750e4d749 132
ThomasBGill 28:b3a597b38b60 133 if(p == 0 ) {
ThomasBGill 22:dae750e4d749 134 if(HugeRat[i][j] == 1) {
ThomasBGill 28:b3a597b38b60 135 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 136 }
ThomasBGill 28:b3a597b38b60 137 } else if(p == 1 ) {
ThomasBGill 28:b3a597b38b60 138 if(Goblin[i][j] == 1) {
ThomasBGill 28:b3a597b38b60 139 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 140 }
ThomasBGill 28:b3a597b38b60 141 } else if(p == 2 ) {
ThomasBGill 28:b3a597b38b60 142 if(Skeleton[i][j] == 1) {
ThomasBGill 28:b3a597b38b60 143 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 144 }
ThomasBGill 28:b3a597b38b60 145 } else if(p == 3 ) {
ThomasBGill 28:b3a597b38b60 146 if(Wraith[i][j] == 1) {
ThomasBGill 28:b3a597b38b60 147 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 148 }
ThomasBGill 28:b3a597b38b60 149 if(rand()%4 == 1) {
ThomasBGill 28:b3a597b38b60 150 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 151 }
ThomasBGill 28:b3a597b38b60 152 } else if(p == 4 ) {
ThomasBGill 28:b3a597b38b60 153 if(Ogre[i][j] == 1) {
ThomasBGill 28:b3a597b38b60 154 lcd.setPixel(y+i, x+j);
ThomasBGill 28:b3a597b38b60 155 }
ThomasBGill 28:b3a597b38b60 156 } else if(p == 5 ) {
ThomasBGill 28:b3a597b38b60 157 if(Minotaur[i][j] == 1) {
ThomasBGill 22:dae750e4d749 158 lcd.setPixel(y+i, x+j);
ThomasBGill 22:dae750e4d749 159 }
ThomasBGill 22:dae750e4d749 160 }
ThomasBGill 22:dae750e4d749 161 }
ThomasBGill 22:dae750e4d749 162 }
ThomasBGill 22:dae750e4d749 163 }
ThomasBGill 0:9200b3c387ed 164
ThomasBGill 28:b3a597b38b60 165 void FlashScreen(int n)
ThomasBGill 28:b3a597b38b60 166 {
ThomasBGill 28:b3a597b38b60 167 for (int i = 0; i<n; i++) {
ThomasBGill 28:b3a597b38b60 168 lcd.inverseMode();
ThomasBGill 28:b3a597b38b60 169 lcd.refresh();
ThomasBGill 28:b3a597b38b60 170 wait(0.2);
ThomasBGill 28:b3a597b38b60 171 lcd.normalMode();
ThomasBGill 28:b3a597b38b60 172 lcd.refresh();
ThomasBGill 28:b3a597b38b60 173 wait(0.2);
ThomasBGill 28:b3a597b38b60 174 }
ThomasBGill 28:b3a597b38b60 175 }
ThomasBGill 28:b3a597b38b60 176
ThomasBGill 28:b3a597b38b60 177 //Game functions
ThomasBGill 28:b3a597b38b60 178
ThomasBGill 21:aa4feee6aa39 179 void Intro()
ThomasBGill 9:3cad581b5419 180 {
ThomasBGill 28:b3a597b38b60 181
ThomasBGill 21:aa4feee6aa39 182 lcd.clear();
ThomasBGill 27:1ad2408ba702 183 lcd.printString("Labyrinth", 15, 1);
ThomasBGill 27:1ad2408ba702 184 lcd.printString("of the", 24, 2);
ThomasBGill 27:1ad2408ba702 185 lcd.printString("Minotaur", 18, 3);
ThomasBGill 9:3cad581b5419 186 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 187 wait(1.0);
ThomasBGill 13:2195ec8bc9ff 188 }
ThomasBGill 9:3cad581b5419 189
ThomasBGill 33:4fc26476b2e0 190 void Initilize()
ThomasBGill 1:0f774d41584c 191 {
ThomasBGill 33:4fc26476b2e0 192
ThomasBGill 23:1b8b1d043403 193 score = -100;
ThomasBGill 23:1b8b1d043403 194
ThomasBGill 21:aa4feee6aa39 195 level = 0;
ThomasBGill 21:aa4feee6aa39 196
ThomasBGill 21:aa4feee6aa39 197 //Player Health
ThomasBGill 30:4a03611a3d99 198 ph = PH_MAX;
ThomasBGill 21:aa4feee6aa39 199
ThomasBGill 21:aa4feee6aa39 200 //Player weapon
ThomasBGill 21:aa4feee6aa39 201 pw = 0; //0 to 4
ThomasBGill 21:aa4feee6aa39 202
ThomasBGill 21:aa4feee6aa39 203 //Player armour
ThomasBGill 21:aa4feee6aa39 204 pa = 5; //5 to 9
ThomasBGill 21:aa4feee6aa39 205
ThomasBGill 33:4fc26476b2e0 206 }
ThomasBGill 33:4fc26476b2e0 207
ThomasBGill 33:4fc26476b2e0 208 void MainMenu()
ThomasBGill 33:4fc26476b2e0 209 {
ThomasBGill 33:4fc26476b2e0 210 Initilize();
ThomasBGill 33:4fc26476b2e0 211
ThomasBGill 23:1b8b1d043403 212 int menu = 0;
ThomasBGill 21:aa4feee6aa39 213
ThomasBGill 21:aa4feee6aa39 214 while (1) {
ThomasBGill 32:99ca304085e6 215
ThomasBGill 32:99ca304085e6 216 ActFlag = 0;
ThomasBGill 32:99ca304085e6 217
ThomasBGill 21:aa4feee6aa39 218 lcd.clear();
ThomasBGill 21:aa4feee6aa39 219 if (menu == 0) {
ThomasBGill 23:1b8b1d043403 220 lcd.printString("New Game <", 6, 1);
ThomasBGill 23:1b8b1d043403 221 lcd.printString("High Scores", 6, 2);
ThomasBGill 23:1b8b1d043403 222 lcd.printString("Options", 6, 3);
ThomasBGill 23:1b8b1d043403 223 lcd.refresh();
ThomasBGill 24:4c4467971c91 224 } else if (menu == 1) {
ThomasBGill 23:1b8b1d043403 225 lcd.printString("New Game", 6, 1);
ThomasBGill 23:1b8b1d043403 226 lcd.printString("High Scores <", 6, 2);
ThomasBGill 23:1b8b1d043403 227 lcd.printString("Options", 6, 3);
ThomasBGill 21:aa4feee6aa39 228 lcd.refresh();
ThomasBGill 22:dae750e4d749 229 } else {
ThomasBGill 23:1b8b1d043403 230 lcd.printString("New Game", 6, 1);
ThomasBGill 23:1b8b1d043403 231 lcd.printString("High Scores", 6, 2);
ThomasBGill 23:1b8b1d043403 232 lcd.printString("Options <", 6, 3);
ThomasBGill 21:aa4feee6aa39 233 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 234 }
ThomasBGill 21:aa4feee6aa39 235
ThomasBGill 32:99ca304085e6 236 Sleep();
ThomasBGill 32:99ca304085e6 237
ThomasBGill 31:5b4a4d225ab4 238 if (joystick.direction == Up) {
ThomasBGill 31:5b4a4d225ab4 239 if(menu > 0) {
ThomasBGill 31:5b4a4d225ab4 240 menu--;
ThomasBGill 31:5b4a4d225ab4 241 }
ThomasBGill 31:5b4a4d225ab4 242 }
ThomasBGill 31:5b4a4d225ab4 243 if(joystick.direction == Down) {
ThomasBGill 31:5b4a4d225ab4 244 if(menu < 3) {
ThomasBGill 31:5b4a4d225ab4 245 menu++;
ThomasBGill 23:1b8b1d043403 246 }
ThomasBGill 21:aa4feee6aa39 247 }
ThomasBGill 21:aa4feee6aa39 248 if (ActFlag) {
ThomasBGill 21:aa4feee6aa39 249
ThomasBGill 21:aa4feee6aa39 250 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 251
ThomasBGill 21:aa4feee6aa39 252 if (menu == 0) {
ThomasBGill 21:aa4feee6aa39 253 GameLoop();
ThomasBGill 23:1b8b1d043403 254 } else if (menu == 1) {
ThomasBGill 23:1b8b1d043403 255 HighScoreScreen();
ThomasBGill 22:dae750e4d749 256 } else {
ThomasBGill 22:dae750e4d749 257 Options();
ThomasBGill 1:0f774d41584c 258 }
ThomasBGill 1:0f774d41584c 259 }
ThomasBGill 1:0f774d41584c 260 }
ThomasBGill 21:aa4feee6aa39 261 }
ThomasBGill 21:aa4feee6aa39 262
ThomasBGill 22:dae750e4d749 263 void Options()
ThomasBGill 22:dae750e4d749 264 {
ThomasBGill 22:dae750e4d749 265
ThomasBGill 22:dae750e4d749 266 bool bright = 1;
ThomasBGill 22:dae750e4d749 267
ThomasBGill 33:4fc26476b2e0 268 lcd.clear();
ThomasBGill 22:dae750e4d749 269 while(1) {
ThomasBGill 22:dae750e4d749 270 if(bright == 1) {
ThomasBGill 22:dae750e4d749 271 lcd.printString("Backlight ON", 6, 2);
ThomasBGill 22:dae750e4d749 272 } else {
ThomasBGill 22:dae750e4d749 273 lcd.printString("Backlight OFF", 6, 2);
ThomasBGill 22:dae750e4d749 274 }
ThomasBGill 23:1b8b1d043403 275
ThomasBGill 22:dae750e4d749 276 lcd.refresh();
ThomasBGill 32:99ca304085e6 277
ThomasBGill 31:5b4a4d225ab4 278 if (joystick.direction != Centre) {
ThomasBGill 22:dae750e4d749 279
ThomasBGill 22:dae750e4d749 280 bright = !bright;
ThomasBGill 33:4fc26476b2e0 281 lcd.setBrightness(bright);
ThomasBGill 33:4fc26476b2e0 282 lcd.clear();
ThomasBGill 22:dae750e4d749 283 }
ThomasBGill 22:dae750e4d749 284 if (ActFlag) {
ThomasBGill 22:dae750e4d749 285 ActFlag = 0;
ThomasBGill 33:4fc26476b2e0 286
ThomasBGill 33:4fc26476b2e0 287 bright = !bright;
ThomasBGill 33:4fc26476b2e0 288 lcd.setBrightness(bright);
ThomasBGill 33:4fc26476b2e0 289 lcd.clear();
ThomasBGill 22:dae750e4d749 290 }
ThomasBGill 22:dae750e4d749 291 if(StartFlag) {
ThomasBGill 22:dae750e4d749 292
ThomasBGill 22:dae750e4d749 293 StartFlag = 0;
ThomasBGill 22:dae750e4d749 294
ThomasBGill 22:dae750e4d749 295 MainMenu();
ThomasBGill 22:dae750e4d749 296
ThomasBGill 22:dae750e4d749 297 }
ThomasBGill 22:dae750e4d749 298 }
ThomasBGill 22:dae750e4d749 299 }
ThomasBGill 22:dae750e4d749 300
ThomasBGill 21:aa4feee6aa39 301 void LevelScreen()
ThomasBGill 21:aa4feee6aa39 302 {
ThomasBGill 21:aa4feee6aa39 303 char buffer[14];
ThomasBGill 21:aa4feee6aa39 304
ThomasBGill 21:aa4feee6aa39 305 int write = sprintf(buffer, "Level %d", level); // print formatted data to buffer
ThomasBGill 21:aa4feee6aa39 306
ThomasBGill 21:aa4feee6aa39 307 lcd.clear();
ThomasBGill 21:aa4feee6aa39 308 lcd.printString(buffer, 20, 2);
ThomasBGill 1:0f774d41584c 309 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 310 wait(1.0);
ThomasBGill 21:aa4feee6aa39 311 }
ThomasBGill 21:aa4feee6aa39 312
ThomasBGill 34:e58c8322884d 313 void NextLevel()
ThomasBGill 34:e58c8322884d 314 {
ThomasBGill 34:e58c8322884d 315
ThomasBGill 34:e58c8322884d 316 level++;
ThomasBGill 34:e58c8322884d 317
ThomasBGill 34:e58c8322884d 318 score = score + 100;
ThomasBGill 34:e58c8322884d 319
ThomasBGill 34:e58c8322884d 320 World();
ThomasBGill 34:e58c8322884d 321
ThomasBGill 34:e58c8322884d 322 LevelScreen();
ThomasBGill 34:e58c8322884d 323
ThomasBGill 34:e58c8322884d 324 //RevealMap(); //Uncomment for debugging to view map
ThomasBGill 34:e58c8322884d 325
ThomasBGill 34:e58c8322884d 326 srand(Noise * 1000000);
ThomasBGill 34:e58c8322884d 327
ThomasBGill 34:e58c8322884d 328 }
ThomasBGill 34:e58c8322884d 329
ThomasBGill 21:aa4feee6aa39 330 void GameLoop()
ThomasBGill 2:0b0311609edc 331 {
ThomasBGill 21:aa4feee6aa39 332 while (1) {
ThomasBGill 21:aa4feee6aa39 333
ThomasBGill 34:e58c8322884d 334 NextLevel();
ThomasBGill 21:aa4feee6aa39 335
ThomasBGill 32:99ca304085e6 336 PlayerCamera();
ThomasBGill 31:5b4a4d225ab4 337
ThomasBGill 31:5b4a4d225ab4 338 while (1) {
ThomasBGill 28:b3a597b38b60 339
ThomasBGill 21:aa4feee6aa39 340 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 341 StartFlag = 0;
ThomasBGill 21:aa4feee6aa39 342
ThomasBGill 35:2c290fa78f1d 343 if (map[px][py] == CHEST) { //If player's current tile is a chest, call the chest function
ThomasBGill 21:aa4feee6aa39 344 Chest();
ThomasBGill 21:aa4feee6aa39 345 }
ThomasBGill 21:aa4feee6aa39 346
ThomasBGill 35:2c290fa78f1d 347 if (px == exx && py == exy) { //If plyer's current tile is the exit
ThomasBGill 21:aa4feee6aa39 348
ThomasBGill 35:2c290fa78f1d 349 if(level%5 == 0) { //If the current level number is a multiple of 5 start a boss fight
ThomasBGill 24:4c4467971c91 350 BossFight = true;
ThomasBGill 24:4c4467971c91 351 Fight();
ThomasBGill 24:4c4467971c91 352 }
ThomasBGill 24:4c4467971c91 353
ThomasBGill 21:aa4feee6aa39 354 break;
ThomasBGill 21:aa4feee6aa39 355
ThomasBGill 21:aa4feee6aa39 356 }
ThomasBGill 21:aa4feee6aa39 357
ThomasBGill 21:aa4feee6aa39 358 Sleep();
ThomasBGill 21:aa4feee6aa39 359
ThomasBGill 21:aa4feee6aa39 360
ThomasBGill 31:5b4a4d225ab4 361 if (joystick.direction != Centre) {
ThomasBGill 21:aa4feee6aa39 362
ThomasBGill 21:aa4feee6aa39 363 PlayerMove();
ThomasBGill 21:aa4feee6aa39 364
ThomasBGill 35:2c290fa78f1d 365 if (rand() % 40 == 0) { //Random chance to heal player as they move
ThomasBGill 29:89bc8c8aa8ac 366 if (ph < PH_MAX) {
ThomasBGill 21:aa4feee6aa39 367 ph++;
ThomasBGill 21:aa4feee6aa39 368 }
ThomasBGill 32:99ca304085e6 369
ThomasBGill 21:aa4feee6aa39 370 }
ThomasBGill 21:aa4feee6aa39 371
ThomasBGill 35:2c290fa78f1d 372 if (rand() % 50 == 0) { //Random chance for fight to start when player moves
ThomasBGill 21:aa4feee6aa39 373 Fight();
ThomasBGill 21:aa4feee6aa39 374 }
ThomasBGill 21:aa4feee6aa39 375
ThomasBGill 32:99ca304085e6 376 PlayerCamera();
ThomasBGill 32:99ca304085e6 377
ThomasBGill 21:aa4feee6aa39 378 }
ThomasBGill 21:aa4feee6aa39 379 if (StartFlag) {
ThomasBGill 21:aa4feee6aa39 380
ThomasBGill 21:aa4feee6aa39 381 StartFlag = 0;
ThomasBGill 21:aa4feee6aa39 382
ThomasBGill 21:aa4feee6aa39 383 StartMenu();
ThomasBGill 32:99ca304085e6 384
ThomasBGill 32:99ca304085e6 385 PlayerCamera();
ThomasBGill 21:aa4feee6aa39 386 }
ThomasBGill 21:aa4feee6aa39 387 if (ActFlag) {
ThomasBGill 21:aa4feee6aa39 388
ThomasBGill 21:aa4feee6aa39 389 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 390 }
ThomasBGill 21:aa4feee6aa39 391 }
ThomasBGill 12:30a242706847 392 }
ThomasBGill 0:9200b3c387ed 393 }
ThomasBGill 0:9200b3c387ed 394
ThomasBGill 8:ee857f0147aa 395 void PlayerCamera()
ThomasBGill 8:ee857f0147aa 396 {
ThomasBGill 8:ee857f0147aa 397 lcd.clear();
ThomasBGill 8:ee857f0147aa 398
ThomasBGill 8:ee857f0147aa 399 int tile;
ThomasBGill 8:ee857f0147aa 400
ThomasBGill 21:aa4feee6aa39 401 for (int i = 0; i < 14; i++) {
ThomasBGill 21:aa4feee6aa39 402 for (int j = 0; j < 6; j++) {
ThomasBGill 8:ee857f0147aa 403
ThomasBGill 21:aa4feee6aa39 404 if (i == 6 && j == 2) {
ThomasBGill 35:2c290fa78f1d 405 lcd.printString("@", (6 * i) + 1, j); //Make player's location a '@' symbol
ThomasBGill 22:dae750e4d749 406 } else {
ThomasBGill 8:ee857f0147aa 407 int diffx = i - 6;
ThomasBGill 8:ee857f0147aa 408 int diffy = j - 2;
ThomasBGill 8:ee857f0147aa 409
ThomasBGill 21:aa4feee6aa39 410 if (px + diffx < 84 && px + diffx > 0 && py + diffy < 48 && py + diffy > 0) {
ThomasBGill 21:aa4feee6aa39 411 tile = map[px + diffx][py + diffy];
ThomasBGill 22:dae750e4d749 412 } else {
ThomasBGill 9:3cad581b5419 413 tile = WALL;
ThomasBGill 9:3cad581b5419 414 }
ThomasBGill 21:aa4feee6aa39 415 lcd.printChar(TileList[tile].Symbol, (6 * i) + 1, j);
ThomasBGill 11:b86a15d26de9 416
ThomasBGill 21:aa4feee6aa39 417 if (map[px + diffx][py + diffy] == FLOOR) {
ThomasBGill 35:2c290fa78f1d 418 map[px + diffx][py + diffy] = FLOOR_SEEN; //Set the floor that has been in view of the player camera to seen to be displayed on the map
ThomasBGill 11:b86a15d26de9 419 }
ThomasBGill 11:b86a15d26de9 420
ThomasBGill 8:ee857f0147aa 421 }
ThomasBGill 8:ee857f0147aa 422 }
ThomasBGill 8:ee857f0147aa 423 }
ThomasBGill 8:ee857f0147aa 424 lcd.refresh();
ThomasBGill 8:ee857f0147aa 425 }
ThomasBGill 8:ee857f0147aa 426
ThomasBGill 8:ee857f0147aa 427 void PlayerMove()
ThomasBGill 8:ee857f0147aa 428 {
ThomasBGill 35:2c290fa78f1d 429 //If direction analogue stick is moved is passable then update the player position
ThomasBGill 35:2c290fa78f1d 430
ThomasBGill 32:99ca304085e6 431 if (joystick.direction == Up) {
ThomasBGill 21:aa4feee6aa39 432 int tile = map[px][py - 1];
ThomasBGill 21:aa4feee6aa39 433 if (TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 434 py--;
ThomasBGill 8:ee857f0147aa 435 }
ThomasBGill 8:ee857f0147aa 436 }
ThomasBGill 32:99ca304085e6 437 if (joystick.direction == Down) {
ThomasBGill 21:aa4feee6aa39 438 int tile = map[px][py + 1];
ThomasBGill 21:aa4feee6aa39 439 if (TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 440 py++;
ThomasBGill 8:ee857f0147aa 441 }
ThomasBGill 8:ee857f0147aa 442 }
ThomasBGill 32:99ca304085e6 443 if (joystick.direction == Right) {
ThomasBGill 21:aa4feee6aa39 444 int tile = map[px + 1][py];
ThomasBGill 21:aa4feee6aa39 445 if (TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 446 px++;
ThomasBGill 8:ee857f0147aa 447 }
ThomasBGill 8:ee857f0147aa 448 }
ThomasBGill 32:99ca304085e6 449 if (joystick.direction == Left) {
ThomasBGill 21:aa4feee6aa39 450 int tile = map[px - 1][py];
ThomasBGill 21:aa4feee6aa39 451 if (TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 452 px--;
ThomasBGill 8:ee857f0147aa 453 }
ThomasBGill 8:ee857f0147aa 454 }
ThomasBGill 13:2195ec8bc9ff 455 }
ThomasBGill 13:2195ec8bc9ff 456
ThomasBGill 13:2195ec8bc9ff 457 void Fight()
ThomasBGill 13:2195ec8bc9ff 458 {
ThomasBGill 24:4c4467971c91 459 int m;
ThomasBGill 28:b3a597b38b60 460
ThomasBGill 24:4c4467971c91 461 lcd.clear();
ThomasBGill 24:4c4467971c91 462
ThomasBGill 24:4c4467971c91 463 if(BossFight) {
ThomasBGill 35:2c290fa78f1d 464 BossFight = false; //Reset BossFight to false
ThomasBGill 24:4c4467971c91 465
ThomasBGill 24:4c4467971c91 466 m = 5; //Monster is a minotaur
ThomasBGill 24:4c4467971c91 467
ThomasBGill 24:4c4467971c91 468 lcd.printString("BOSS!", 30, 2);
ThomasBGill 35:2c290fa78f1d 469 } else { //If not a boss fight randomly choose a monster to fight
ThomasBGill 24:4c4467971c91 470
ThomasBGill 35:2c290fa78f1d 471 //Lvl 1- Huge Rat + Goblin, Lvl 2 +Skeleton, Lvl 3 +Wraith, Lvl 4 +Ogre
ThomasBGill 24:4c4467971c91 472 int mr = level + 1;
ThomasBGill 24:4c4467971c91 473
ThomasBGill 30:4a03611a3d99 474 if (mr > 5) {
ThomasBGill 30:4a03611a3d99 475 mr = 5;
ThomasBGill 24:4c4467971c91 476 }
ThomasBGill 24:4c4467971c91 477
ThomasBGill 28:b3a597b38b60 478 lcd.printString("FIGHT!", 24, 2);
ThomasBGill 28:b3a597b38b60 479
ThomasBGill 24:4c4467971c91 480 m = rand() % mr;
ThomasBGill 24:4c4467971c91 481 }
ThomasBGill 13:2195ec8bc9ff 482
ThomasBGill 34:e58c8322884d 483 mh = EnemyList[m].EHealth;
ThomasBGill 13:2195ec8bc9ff 484
ThomasBGill 28:b3a597b38b60 485 FlashScreen(5);
ThomasBGill 28:b3a597b38b60 486
ThomasBGill 28:b3a597b38b60 487 char buffer1[14];
ThomasBGill 28:b3a597b38b60 488 int write = sprintf(buffer1, "%d/%d", mh, EnemyList[m].EHealth); // print formatted data to buffer
ThomasBGill 13:2195ec8bc9ff 489
ThomasBGill 28:b3a597b38b60 490 lcd.clear();
ThomasBGill 35:2c290fa78f1d 491 lcd.printString(EnemyList[m].EName, 0, 0);
ThomasBGill 35:2c290fa78f1d 492 lcd.printString(buffer1, 54, 0); //Current enemy health/max enemy health
ThomasBGill 35:2c290fa78f1d 493 DrawGraphic(m, 23, 7); //Image of monster
ThomasBGill 28:b3a597b38b60 494 lcd.refresh();
ThomasBGill 28:b3a597b38b60 495 wait(2.0);
ThomasBGill 22:dae750e4d749 496
ThomasBGill 13:2195ec8bc9ff 497 bool menu = 1;
ThomasBGill 13:2195ec8bc9ff 498
ThomasBGill 21:aa4feee6aa39 499 while (1) {
ThomasBGill 13:2195ec8bc9ff 500 ActFlag = 0;
ThomasBGill 13:2195ec8bc9ff 501 StartFlag = 0;
ThomasBGill 13:2195ec8bc9ff 502
ThomasBGill 13:2195ec8bc9ff 503 lcd.clear();
ThomasBGill 13:2195ec8bc9ff 504
ThomasBGill 13:2195ec8bc9ff 505 lcd.printString(EnemyList[m].EName, 0, 0);
ThomasBGill 28:b3a597b38b60 506 write = sprintf(buffer1, "%d/%d", mh, EnemyList[m].EHealth); // print formatted data to buffer
ThomasBGill 35:2c290fa78f1d 507 lcd.printString(buffer1, 54, 0); //Current enemy health/max enemy health
ThomasBGill 13:2195ec8bc9ff 508
ThomasBGill 13:2195ec8bc9ff 509 lcd.printString("You", 0, 2);
ThomasBGill 13:2195ec8bc9ff 510 char buffer2[14];
ThomasBGill 29:89bc8c8aa8ac 511 int phm = PH_MAX;
ThomasBGill 29:89bc8c8aa8ac 512 write = sprintf(buffer2, "%d/%d", ph, phm); // print formatted data to buffer
ThomasBGill 35:2c290fa78f1d 513 lcd.printString(buffer2, 54, 2); //Current player health/max player health
ThomasBGill 13:2195ec8bc9ff 514
ThomasBGill 21:aa4feee6aa39 515 if (menu) {
ThomasBGill 13:2195ec8bc9ff 516 lcd.printString("Fight <", 0, 4);
ThomasBGill 13:2195ec8bc9ff 517 lcd.printString("Run", 0, 5);
ThomasBGill 22:dae750e4d749 518 } else {
ThomasBGill 13:2195ec8bc9ff 519 lcd.printString("Fight", 0, 4);
ThomasBGill 13:2195ec8bc9ff 520 lcd.printString("Run <", 0, 5);
ThomasBGill 13:2195ec8bc9ff 521 }
ThomasBGill 13:2195ec8bc9ff 522 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 523 Sleep();
ThomasBGill 13:2195ec8bc9ff 524
ThomasBGill 31:5b4a4d225ab4 525 if (joystick.direction != Centre) {
ThomasBGill 13:2195ec8bc9ff 526 menu = !menu;
ThomasBGill 13:2195ec8bc9ff 527 }
ThomasBGill 21:aa4feee6aa39 528 if (ActFlag) {
ThomasBGill 13:2195ec8bc9ff 529 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 530 if (menu) { //Fight
ThomasBGill 13:2195ec8bc9ff 531
ThomasBGill 34:e58c8322884d 532 PlayerAttack(m);
ThomasBGill 13:2195ec8bc9ff 533
ThomasBGill 21:aa4feee6aa39 534 if (mh <= 0) { //Check if monster is dead
ThomasBGill 23:1b8b1d043403 535 score = score + EnemyList[m].EPoints;
ThomasBGill 13:2195ec8bc9ff 536 lcd.clear();
ThomasBGill 15:05a227f970c2 537 lcd.printString("You win!", 18, 2);
ThomasBGill 13:2195ec8bc9ff 538 lcd.refresh();
ThomasBGill 15:05a227f970c2 539 wait(1.0);
ThomasBGill 13:2195ec8bc9ff 540 Sleep();
ThomasBGill 13:2195ec8bc9ff 541 break;
ThomasBGill 13:2195ec8bc9ff 542 }
ThomasBGill 13:2195ec8bc9ff 543
ThomasBGill 16:a26d7519830e 544 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 545
ThomasBGill 13:2195ec8bc9ff 546
ThomasBGill 22:dae750e4d749 547 } else { //Run away
ThomasBGill 15:05a227f970c2 548
ThomasBGill 23:1b8b1d043403 549 score = score - 2;
ThomasBGill 23:1b8b1d043403 550
ThomasBGill 21:aa4feee6aa39 551 int b = rand() % 5;
ThomasBGill 16:a26d7519830e 552
ThomasBGill 21:aa4feee6aa39 553 if (b == 0) { //Monster blocks the path
ThomasBGill 15:05a227f970c2 554
ThomasBGill 15:05a227f970c2 555 lcd.clear();
ThomasBGill 16:a26d7519830e 556 lcd.printString("You try to run", 0, 0);
ThomasBGill 16:a26d7519830e 557 lcd.printString("away but the", 0, 1);
ThomasBGill 16:a26d7519830e 558 lcd.printString("monster blocks", 0, 2);
ThomasBGill 16:a26d7519830e 559 lcd.printString("the path", 0, 3);
ThomasBGill 15:05a227f970c2 560 lcd.refresh();
ThomasBGill 15:05a227f970c2 561 wait(1.0);
ThomasBGill 15:05a227f970c2 562 Sleep();
ThomasBGill 15:05a227f970c2 563
ThomasBGill 16:a26d7519830e 564 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 565
ThomasBGill 35:2c290fa78f1d 566 } else { //Monster doesn't block the path
ThomasBGill 16:a26d7519830e 567
ThomasBGill 21:aa4feee6aa39 568 int s = rand() % 100 + 1;
ThomasBGill 16:a26d7519830e 569
ThomasBGill 21:aa4feee6aa39 570 if (s > EnemyList[m].ESpd) { //If you outspeed monster
ThomasBGill 16:a26d7519830e 571
ThomasBGill 16:a26d7519830e 572 lcd.clear();
ThomasBGill 16:a26d7519830e 573 lcd.printString("You run away", 6, 2);
ThomasBGill 16:a26d7519830e 574 lcd.refresh();
ThomasBGill 17:8790dd599b25 575 wait(1.0);
ThomasBGill 16:a26d7519830e 576 Sleep();
ThomasBGill 16:a26d7519830e 577 break;
ThomasBGill 16:a26d7519830e 578
ThomasBGill 35:2c290fa78f1d 579 } else { //You don't outspeed the monster and it attacks you
ThomasBGill 16:a26d7519830e 580
ThomasBGill 16:a26d7519830e 581 lcd.clear();
ThomasBGill 16:a26d7519830e 582 lcd.printString("You try to run", 0, 0);
ThomasBGill 16:a26d7519830e 583 lcd.printString("away but the", 0, 1);
ThomasBGill 16:a26d7519830e 584 lcd.printString("monster", 0, 2);
ThomasBGill 16:a26d7519830e 585 lcd.printString("catches up to", 0, 3);
ThomasBGill 16:a26d7519830e 586 lcd.printString("you", 0, 4);
ThomasBGill 16:a26d7519830e 587 lcd.refresh();
ThomasBGill 16:a26d7519830e 588 wait(1.0);
ThomasBGill 16:a26d7519830e 589 Sleep();
ThomasBGill 16:a26d7519830e 590
ThomasBGill 16:a26d7519830e 591 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 592
ThomasBGill 16:a26d7519830e 593 }
ThomasBGill 8:ee857f0147aa 594
ThomasBGill 9:3cad581b5419 595
ThomasBGill 16:a26d7519830e 596 }
ThomasBGill 13:2195ec8bc9ff 597 }
ThomasBGill 13:2195ec8bc9ff 598 }
ThomasBGill 13:2195ec8bc9ff 599 }
ThomasBGill 13:2195ec8bc9ff 600 }
ThomasBGill 13:2195ec8bc9ff 601
ThomasBGill 34:e58c8322884d 602 void PlayerAttack(int m)
ThomasBGill 34:e58c8322884d 603 {
ThomasBGill 34:e58c8322884d 604
ThomasBGill 34:e58c8322884d 605 //Hit monster
ThomasBGill 34:e58c8322884d 606 if (rand() % 100 + 1 > EnemyList[m].EDodge) { //If monster doesn't dodge
ThomasBGill 34:e58c8322884d 607
ThomasBGill 34:e58c8322884d 608 int damage = ItemList[pw].ItemValue - EnemyList[m].EArmour + rand() % 3 - rand() % 3; //Calculate damage
ThomasBGill 34:e58c8322884d 609 if (damage < 0) {
ThomasBGill 34:e58c8322884d 610 damage = 0;
ThomasBGill 34:e58c8322884d 611 }
ThomasBGill 34:e58c8322884d 612 mh = mh - damage; //Apply damage and calculate the monster's health
ThomasBGill 34:e58c8322884d 613
ThomasBGill 34:e58c8322884d 614 char damBuffer[14];
ThomasBGill 34:e58c8322884d 615 int write = sprintf(damBuffer,"-%d", damage);
ThomasBGill 34:e58c8322884d 616
ThomasBGill 35:2c290fa78f1d 617 //Flash image of monster on the screen with the amount of damage it recieved
ThomasBGill 34:e58c8322884d 618 lcd.clear();
ThomasBGill 34:e58c8322884d 619 DrawGraphic(m, 23, 7);
ThomasBGill 34:e58c8322884d 620 lcd.printString(damBuffer, 62, 2);
ThomasBGill 34:e58c8322884d 621 FlashScreen(3);
ThomasBGill 34:e58c8322884d 622
ThomasBGill 34:e58c8322884d 623
ThomasBGill 34:e58c8322884d 624 char buffer3[14];
ThomasBGill 34:e58c8322884d 625 write = sprintf(buffer3, "for %d damage", damage); // print formatted data to buffer
ThomasBGill 34:e58c8322884d 626
ThomasBGill 34:e58c8322884d 627 lcd.clear();
ThomasBGill 34:e58c8322884d 628 lcd.printString("You hit the", 0, 1);
ThomasBGill 34:e58c8322884d 629 lcd.printString(EnemyList[m].EName, 0, 2);
ThomasBGill 34:e58c8322884d 630 lcd.printString(buffer3, 0, 3);
ThomasBGill 34:e58c8322884d 631 lcd.refresh();
ThomasBGill 34:e58c8322884d 632 wait(1.0);
ThomasBGill 34:e58c8322884d 633 Sleep();
ThomasBGill 34:e58c8322884d 634
ThomasBGill 34:e58c8322884d 635 } else { //Monster dodges
ThomasBGill 34:e58c8322884d 636 lcd.clear();
ThomasBGill 34:e58c8322884d 637 lcd.printString(EnemyList[m].EName, 0, 1);
ThomasBGill 34:e58c8322884d 638 lcd.printString("dodges your", 0, 2);
ThomasBGill 34:e58c8322884d 639 lcd.printString("attack", 0, 3);
ThomasBGill 34:e58c8322884d 640 lcd.refresh();
ThomasBGill 34:e58c8322884d 641 wait(1.0);
ThomasBGill 34:e58c8322884d 642 Sleep();
ThomasBGill 34:e58c8322884d 643 }
ThomasBGill 34:e58c8322884d 644 }
ThomasBGill 34:e58c8322884d 645
ThomasBGill 21:aa4feee6aa39 646 void MonsterAttack(int m)
ThomasBGill 13:2195ec8bc9ff 647 {
ThomasBGill 21:aa4feee6aa39 648 if (rand() % 100 + 1 < EnemyList[m].EHit) { //If monster hits and isn't dead
ThomasBGill 21:aa4feee6aa39 649
ThomasBGill 21:aa4feee6aa39 650 int damage = EnemyList[m].EDamage - ItemList[pa].ItemValue + rand() % 3 - rand() % 3; //Calculate damage
ThomasBGill 21:aa4feee6aa39 651 if (damage < 0) {
ThomasBGill 21:aa4feee6aa39 652 damage = 0;
ThomasBGill 21:aa4feee6aa39 653 }
ThomasBGill 21:aa4feee6aa39 654 ph = ph - damage; //Apply damage and calculate the monster's health
ThomasBGill 13:2195ec8bc9ff 655
ThomasBGill 21:aa4feee6aa39 656 char buffer[14];
ThomasBGill 21:aa4feee6aa39 657 int write = sprintf(buffer, "%d damage", damage); // print formatted data to buffer
ThomasBGill 14:55802ce40285 658
ThomasBGill 21:aa4feee6aa39 659 lcd.clear();
ThomasBGill 21:aa4feee6aa39 660 lcd.printString(EnemyList[m].EName, 0, 1);
ThomasBGill 21:aa4feee6aa39 661 lcd.printString("hits you for", 0, 2);
ThomasBGill 21:aa4feee6aa39 662 lcd.printString(buffer, 0, 3);
ThomasBGill 21:aa4feee6aa39 663 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 664 wait(1.0);
ThomasBGill 14:55802ce40285 665 Sleep();
ThomasBGill 14:55802ce40285 666
ThomasBGill 22:dae750e4d749 667 } else { //You dodge
ThomasBGill 21:aa4feee6aa39 668 lcd.clear();
ThomasBGill 21:aa4feee6aa39 669 lcd.printString("You dodge the", 0, 1);
ThomasBGill 21:aa4feee6aa39 670 lcd.printString("monster's", 0, 2);
ThomasBGill 21:aa4feee6aa39 671 lcd.printString("attack", 0, 3);
ThomasBGill 21:aa4feee6aa39 672 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 673 wait(1.0);
ThomasBGill 21:aa4feee6aa39 674 Sleep();
ThomasBGill 21:aa4feee6aa39 675 }
ThomasBGill 21:aa4feee6aa39 676 if (ph <= 0) { //Check if player is dead
ThomasBGill 21:aa4feee6aa39 677 GameOver();
ThomasBGill 21:aa4feee6aa39 678 }
ThomasBGill 14:55802ce40285 679
ThomasBGill 8:ee857f0147aa 680 }
ThomasBGill 8:ee857f0147aa 681
ThomasBGill 9:3cad581b5419 682 void StartMenu()
ThomasBGill 9:3cad581b5419 683 {
ThomasBGill 13:2195ec8bc9ff 684 int menu = 0;
ThomasBGill 9:3cad581b5419 685
ThomasBGill 14:55802ce40285 686 char buffer[14];
ThomasBGill 29:89bc8c8aa8ac 687 int phm = PH_MAX;
ThomasBGill 29:89bc8c8aa8ac 688 int write = sprintf(buffer, "Health %d/%d", ph, phm); // print formatted data to buffer
ThomasBGill 14:55802ce40285 689
ThomasBGill 14:55802ce40285 690
ThomasBGill 21:aa4feee6aa39 691 while (1) {
ThomasBGill 21:aa4feee6aa39 692 if (menu == 0) {
ThomasBGill 13:2195ec8bc9ff 693 lcd.clear();
ThomasBGill 35:2c290fa78f1d 694 lcd.printString(buffer, 0, 0); //Player current/max health
ThomasBGill 14:55802ce40285 695 lcd.printString("Map <", 0, 2);
ThomasBGill 14:55802ce40285 696 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 697 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 698 lcd.printString("Continue", 0, 5);
ThomasBGill 13:2195ec8bc9ff 699 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 700 Sleep();
ThomasBGill 22:dae750e4d749 701 } else if (menu == 1) {
ThomasBGill 13:2195ec8bc9ff 702 lcd.clear();
ThomasBGill 35:2c290fa78f1d 703 lcd.printString(buffer, 0, 0); //Player current/max health
ThomasBGill 35:2c290fa78f1d 704 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 705 lcd.printString("Map Legend <", 0, 3);
ThomasBGill 14:55802ce40285 706 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 707 lcd.printString("Continue", 0, 5);
ThomasBGill 13:2195ec8bc9ff 708 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 709 Sleep();
ThomasBGill 22:dae750e4d749 710 } else if (menu == 2) {
ThomasBGill 13:2195ec8bc9ff 711 lcd.clear();
ThomasBGill 35:2c290fa78f1d 712 lcd.printString(buffer, 0, 0); //Player current/max health
ThomasBGill 14:55802ce40285 713 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 714 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 715 lcd.printString("Inventory <", 0, 4);
ThomasBGill 14:55802ce40285 716 lcd.printString("Continue", 0, 5);
ThomasBGill 14:55802ce40285 717 lcd.refresh();
ThomasBGill 14:55802ce40285 718 Sleep();
ThomasBGill 22:dae750e4d749 719 } else if (menu == 3) {
ThomasBGill 14:55802ce40285 720 lcd.clear();
ThomasBGill 35:2c290fa78f1d 721 lcd.printString(buffer, 0, 0); //Player current/max health
ThomasBGill 14:55802ce40285 722 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 723 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 724 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 725 lcd.printString("Continue <", 0, 5);
ThomasBGill 13:2195ec8bc9ff 726 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 727 Sleep();
ThomasBGill 9:3cad581b5419 728 }
ThomasBGill 13:2195ec8bc9ff 729
ThomasBGill 31:5b4a4d225ab4 730 if (joystick.direction != Centre) {
ThomasBGill 31:5b4a4d225ab4 731
ThomasBGill 31:5b4a4d225ab4 732 if ((joystick.direction == Down || joystick.direction == Right) && menu < 3) {
ThomasBGill 13:2195ec8bc9ff 733 menu++;
ThomasBGill 31:5b4a4d225ab4 734 } else if ((joystick.direction == Up || joystick.direction == Left) && menu > 0)
ThomasBGill 13:2195ec8bc9ff 735 menu--;
ThomasBGill 13:2195ec8bc9ff 736 }
ThomasBGill 21:aa4feee6aa39 737 if (ActFlag) {
ThomasBGill 13:2195ec8bc9ff 738 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 739 if (menu == 0) {
ThomasBGill 13:2195ec8bc9ff 740 Map();
ThomasBGill 22:dae750e4d749 741 } else if (menu == 1) {
ThomasBGill 14:55802ce40285 742 MapLegend();
ThomasBGill 22:dae750e4d749 743 } else if (menu == 2) {
ThomasBGill 13:2195ec8bc9ff 744 Inventory();
ThomasBGill 22:dae750e4d749 745 } else {
ThomasBGill 13:2195ec8bc9ff 746 break;
ThomasBGill 13:2195ec8bc9ff 747 }
ThomasBGill 13:2195ec8bc9ff 748 }
ThomasBGill 21:aa4feee6aa39 749 if (StartFlag) {
ThomasBGill 16:a26d7519830e 750 StartFlag = 0;
ThomasBGill 16:a26d7519830e 751 }
ThomasBGill 9:3cad581b5419 752 }
ThomasBGill 10:59c874d006ab 753 }
ThomasBGill 9:3cad581b5419 754
ThomasBGill 21:aa4feee6aa39 755 void Map()
ThomasBGill 10:59c874d006ab 756 {
ThomasBGill 10:59c874d006ab 757 lcd.clear();
ThomasBGill 21:aa4feee6aa39 758 DrawMap();
ThomasBGill 21:aa4feee6aa39 759 while (!StartFlag) {
ThomasBGill 21:aa4feee6aa39 760 FlashPlayerLocation();
ThomasBGill 21:aa4feee6aa39 761 }
ThomasBGill 21:aa4feee6aa39 762 StartFlag = 0;
ThomasBGill 21:aa4feee6aa39 763 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 764 }
ThomasBGill 21:aa4feee6aa39 765
ThomasBGill 21:aa4feee6aa39 766 void DrawMap()
ThomasBGill 21:aa4feee6aa39 767 {
ThomasBGill 21:aa4feee6aa39 768 //Draw map on screen
ThomasBGill 21:aa4feee6aa39 769 for (int i = 0; i<84; i++) {
ThomasBGill 21:aa4feee6aa39 770 for (int j = 0; j<48; j++) {
ThomasBGill 21:aa4feee6aa39 771 if (map[i][j] == FLOOR_SEEN || map[i][j] == CHEST_OPENED) {
ThomasBGill 21:aa4feee6aa39 772 lcd.clearPixel(i, j);
ThomasBGill 22:dae750e4d749 773 } else {
ThomasBGill 21:aa4feee6aa39 774 lcd.setPixel(i, j);
ThomasBGill 21:aa4feee6aa39 775 }
ThomasBGill 21:aa4feee6aa39 776 }
ThomasBGill 21:aa4feee6aa39 777 }
ThomasBGill 10:59c874d006ab 778 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 779 }
ThomasBGill 21:aa4feee6aa39 780
ThomasBGill 21:aa4feee6aa39 781 void FlashPlayerLocation()
ThomasBGill 21:aa4feee6aa39 782 {
ThomasBGill 21:aa4feee6aa39 783 lcd.setPixel(px, py);
ThomasBGill 21:aa4feee6aa39 784 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 785 wait(0.5);
ThomasBGill 21:aa4feee6aa39 786 lcd.clearPixel(px, py);
ThomasBGill 21:aa4feee6aa39 787 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 788 wait(0.5);
ThomasBGill 10:59c874d006ab 789 }
ThomasBGill 10:59c874d006ab 790
ThomasBGill 21:aa4feee6aa39 791 void MapLegend()
ThomasBGill 10:59c874d006ab 792 {
ThomasBGill 21:aa4feee6aa39 793 lcd.clear();
ThomasBGill 21:aa4feee6aa39 794 lcd.printString("@ Player", 0, 0);
ThomasBGill 21:aa4feee6aa39 795 lcd.printString("# Wall", 0, 1);
ThomasBGill 21:aa4feee6aa39 796 lcd.printString(". Floor", 0, 2);
ThomasBGill 21:aa4feee6aa39 797 lcd.printString("= Chest", 0, 3);
ThomasBGill 21:aa4feee6aa39 798 lcd.printString("/ Open Chest", 0, 4);
ThomasBGill 21:aa4feee6aa39 799
ThomasBGill 21:aa4feee6aa39 800
ThomasBGill 21:aa4feee6aa39 801 while (1) {
ThomasBGill 21:aa4feee6aa39 802 Sleep();
ThomasBGill 21:aa4feee6aa39 803
ThomasBGill 21:aa4feee6aa39 804 if (ActFlag) {
ThomasBGill 21:aa4feee6aa39 805 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 806 }
ThomasBGill 21:aa4feee6aa39 807 if (StartFlag) {
ThomasBGill 21:aa4feee6aa39 808 StartFlag = 0;
ThomasBGill 21:aa4feee6aa39 809 break;
ThomasBGill 21:aa4feee6aa39 810 }
ThomasBGill 21:aa4feee6aa39 811 }
ThomasBGill 21:aa4feee6aa39 812 }
ThomasBGill 21:aa4feee6aa39 813
ThomasBGill 21:aa4feee6aa39 814 void Inventory()
ThomasBGill 21:aa4feee6aa39 815 {
ThomasBGill 21:aa4feee6aa39 816 lcd.clear();
ThomasBGill 21:aa4feee6aa39 817 lcd.printString("Armour:", 0, 0);
ThomasBGill 35:2c290fa78f1d 818 lcd.printString(ItemList[pa].ItemName, 0, 1); //Current armour
ThomasBGill 21:aa4feee6aa39 819 char buffer1[14];
ThomasBGill 21:aa4feee6aa39 820 int write = sprintf(buffer1, "+%d Armour", ItemList[pa].ItemValue); // print formatted data to buffer
ThomasBGill 35:2c290fa78f1d 821 lcd.printString(buffer1, 0, 2); //Current armour value
ThomasBGill 12:30a242706847 822
ThomasBGill 21:aa4feee6aa39 823 lcd.printString("Weapon:", 0, 3);
ThomasBGill 35:2c290fa78f1d 824 lcd.printString(ItemList[pw].ItemName, 0, 4); //Current weapon
ThomasBGill 21:aa4feee6aa39 825 char buffer2[14];
ThomasBGill 21:aa4feee6aa39 826 write = sprintf(buffer2, "+%d Damage", ItemList[pw].ItemValue); // print formatted data to buffer
ThomasBGill 35:2c290fa78f1d 827 lcd.printString(buffer2, 0, 5); //Current weapon value
ThomasBGill 21:aa4feee6aa39 828 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 829
ThomasBGill 21:aa4feee6aa39 830 while (1) {
ThomasBGill 21:aa4feee6aa39 831 Sleep();
ThomasBGill 11:b86a15d26de9 832
ThomasBGill 21:aa4feee6aa39 833 if (ActFlag) {
ThomasBGill 21:aa4feee6aa39 834 ActFlag = 0;
ThomasBGill 21:aa4feee6aa39 835 }
ThomasBGill 21:aa4feee6aa39 836 if (StartFlag) {
ThomasBGill 21:aa4feee6aa39 837 StartFlag = 0;
ThomasBGill 21:aa4feee6aa39 838 break;
ThomasBGill 21:aa4feee6aa39 839 }
ThomasBGill 21:aa4feee6aa39 840 }
ThomasBGill 21:aa4feee6aa39 841 }
ThomasBGill 21:aa4feee6aa39 842
ThomasBGill 21:aa4feee6aa39 843 void Chest()
ThomasBGill 21:aa4feee6aa39 844 {
ThomasBGill 23:1b8b1d043403 845 score = score + 10;
ThomasBGill 23:1b8b1d043403 846
ThomasBGill 35:2c290fa78f1d 847 //Generate what is in the chest
ThomasBGill 21:aa4feee6aa39 848 int c = rand() % 4; //0- Item, 1- Booby trap, 2- Map, Else- Potion
ThomasBGill 21:aa4feee6aa39 849
ThomasBGill 21:aa4feee6aa39 850 if (c == 0) {
ThomasBGill 21:aa4feee6aa39 851 getItem();
ThomasBGill 22:dae750e4d749 852 } else if (c == 1) {
ThomasBGill 21:aa4feee6aa39 853 BoobyTrap();
ThomasBGill 22:dae750e4d749 854 } else if (c == 2) {
ThomasBGill 21:aa4feee6aa39 855 RevealMap();
ThomasBGill 22:dae750e4d749 856 } else {
ThomasBGill 21:aa4feee6aa39 857 Potion();
ThomasBGill 21:aa4feee6aa39 858 }
ThomasBGill 21:aa4feee6aa39 859
ThomasBGill 35:2c290fa78f1d 860 map[px][py] = CHEST_OPENED; //Change the current tile to CHEST_OPENED
ThomasBGill 10:59c874d006ab 861
ThomasBGill 10:59c874d006ab 862 }
ThomasBGill 10:59c874d006ab 863
ThomasBGill 15:05a227f970c2 864 void getItem()
ThomasBGill 12:30a242706847 865 {
ThomasBGill 35:2c290fa78f1d 866 //Generate item from ItemList
ThomasBGill 21:aa4feee6aa39 867 int r = rand() % 10;
ThomasBGill 12:30a242706847 868
ThomasBGill 15:05a227f970c2 869 lcd.clear();
ThomasBGill 15:05a227f970c2 870 lcd.printString("Do you want to", 0, 1);
ThomasBGill 15:05a227f970c2 871 lcd.printString("take the", 0, 2);
ThomasBGill 15:05a227f970c2 872 lcd.printString(ItemList[r].ItemName, 0, 3);
ThomasBGill 15:05a227f970c2 873 lcd.printString("-Yes (Action)", 0, 4);
ThomasBGill 32:99ca304085e6 874 lcd.printString("-No (Start)", 0, 5);
ThomasBGill 15:05a227f970c2 875 lcd.refresh();
ThomasBGill 16:a26d7519830e 876 wait(1.0);
ThomasBGill 15:05a227f970c2 877
ThomasBGill 32:99ca304085e6 878 while(1) {
ThomasBGill 16:a26d7519830e 879 Sleep();
ThomasBGill 15:05a227f970c2 880
ThomasBGill 35:2c290fa78f1d 881 if (ActFlag) { //Take item
ThomasBGill 32:99ca304085e6 882
ThomasBGill 32:99ca304085e6 883 ActFlag = 0;
ThomasBGill 32:99ca304085e6 884
ThomasBGill 32:99ca304085e6 885 if (r > 5) {
ThomasBGill 32:99ca304085e6 886 pa = r;
ThomasBGill 32:99ca304085e6 887 } else {
ThomasBGill 32:99ca304085e6 888 pw = r;
ThomasBGill 32:99ca304085e6 889 }
ThomasBGill 16:a26d7519830e 890
ThomasBGill 32:99ca304085e6 891 lcd.clear();
ThomasBGill 32:99ca304085e6 892 lcd.printString("You take the", 0, 1);
ThomasBGill 32:99ca304085e6 893 lcd.printString(ItemList[r].ItemName, 0, 2);
ThomasBGill 32:99ca304085e6 894 lcd.refresh();
ThomasBGill 32:99ca304085e6 895 wait(1.0);
ThomasBGill 32:99ca304085e6 896 Sleep();
ThomasBGill 32:99ca304085e6 897
ThomasBGill 32:99ca304085e6 898 }
ThomasBGill 35:2c290fa78f1d 899 if(StartFlag) { //Leave item
ThomasBGill 32:99ca304085e6 900
ThomasBGill 32:99ca304085e6 901 StartFlag = 0;
ThomasBGill 32:99ca304085e6 902
ThomasBGill 32:99ca304085e6 903 lcd.clear();
ThomasBGill 32:99ca304085e6 904 lcd.printString("You leave the", 0, 1);
ThomasBGill 32:99ca304085e6 905 lcd.printString(ItemList[r].ItemName, 0, 2);
ThomasBGill 32:99ca304085e6 906 lcd.refresh();
ThomasBGill 32:99ca304085e6 907 wait(1.0);
ThomasBGill 32:99ca304085e6 908 Sleep();
ThomasBGill 32:99ca304085e6 909 }
ThomasBGill 15:05a227f970c2 910 }
ThomasBGill 15:05a227f970c2 911 }
ThomasBGill 15:05a227f970c2 912
ThomasBGill 15:05a227f970c2 913 void BoobyTrap()
ThomasBGill 15:05a227f970c2 914 {
ThomasBGill 35:2c290fa78f1d 915 //Generate damage
ThomasBGill 21:aa4feee6aa39 916 int damage = rand() % 5;
ThomasBGill 15:05a227f970c2 917
ThomasBGill 21:aa4feee6aa39 918 if (damage != 0) {
ThomasBGill 15:05a227f970c2 919
ThomasBGill 15:05a227f970c2 920 ph = ph - damage;
ThomasBGill 15:05a227f970c2 921
ThomasBGill 15:05a227f970c2 922 char buffer[15];
ThomasBGill 15:05a227f970c2 923 int write = sprintf(buffer, "You recive %d", damage);
ThomasBGill 15:05a227f970c2 924
ThomasBGill 15:05a227f970c2 925 lcd.clear();
ThomasBGill 15:05a227f970c2 926 lcd.printString("The chest is", 0, 0);
ThomasBGill 16:a26d7519830e 927 lcd.printString("booby trapped!", 0, 1);
ThomasBGill 15:05a227f970c2 928 lcd.printString(buffer, 0, 3);
ThomasBGill 15:05a227f970c2 929 lcd.printString("damage", 0, 4);
ThomasBGill 15:05a227f970c2 930 lcd.refresh();
ThomasBGill 15:05a227f970c2 931 wait(1.0);
ThomasBGill 13:2195ec8bc9ff 932 Sleep();
ThomasBGill 12:30a242706847 933
ThomasBGill 15:05a227f970c2 934 //Check if player is dead
ThomasBGill 21:aa4feee6aa39 935 if (ph < 0) {
ThomasBGill 15:05a227f970c2 936 GameOver();
ThomasBGill 15:05a227f970c2 937 }
ThomasBGill 22:dae750e4d749 938 } else {
ThomasBGill 12:30a242706847 939
ThomasBGill 15:05a227f970c2 940 lcd.clear();
ThomasBGill 15:05a227f970c2 941 lcd.printString("The chest is", 0, 0);
ThomasBGill 16:a26d7519830e 942 lcd.printString("booby trapped", 0, 1);
ThomasBGill 16:a26d7519830e 943 lcd.printString("but the trap", 0, 2);
ThomasBGill 16:a26d7519830e 944 lcd.printString("fails", 0, 3);
ThomasBGill 15:05a227f970c2 945 lcd.refresh();
ThomasBGill 15:05a227f970c2 946 wait(1.0);
ThomasBGill 15:05a227f970c2 947 Sleep();
ThomasBGill 15:05a227f970c2 948
ThomasBGill 15:05a227f970c2 949 }
ThomasBGill 15:05a227f970c2 950 }
ThomasBGill 13:2195ec8bc9ff 951
ThomasBGill 15:05a227f970c2 952 void RevealMap()
ThomasBGill 15:05a227f970c2 953 {
ThomasBGill 35:2c290fa78f1d 954 //Iterates through each cell in the array, changing any unseen floor tiles to seen ones
ThomasBGill 21:aa4feee6aa39 955 for (int i = 0; i < 84; i++) {
ThomasBGill 21:aa4feee6aa39 956 for (int j = 0; j < 48; j++) {
ThomasBGill 15:05a227f970c2 957
ThomasBGill 21:aa4feee6aa39 958 if (map[i][j] == FLOOR) {
ThomasBGill 15:05a227f970c2 959 map[i][j] = FLOOR_SEEN;
ThomasBGill 15:05a227f970c2 960 }
ThomasBGill 15:05a227f970c2 961 }
ThomasBGill 15:05a227f970c2 962 }
ThomasBGill 12:30a242706847 963
ThomasBGill 15:05a227f970c2 964 lcd.clear();
ThomasBGill 15:05a227f970c2 965 lcd.printString("You find a map", 0, 0);
ThomasBGill 16:a26d7519830e 966 lcd.printString("of the current", 0, 1);
ThomasBGill 16:a26d7519830e 967 lcd.printString("level inside", 0, 2);
ThomasBGill 16:a26d7519830e 968 lcd.printString("the chest", 0, 3);
ThomasBGill 15:05a227f970c2 969 lcd.refresh();
ThomasBGill 15:05a227f970c2 970 wait(1.0);
ThomasBGill 15:05a227f970c2 971 Sleep();
ThomasBGill 15:05a227f970c2 972 }
ThomasBGill 15:05a227f970c2 973
ThomasBGill 15:05a227f970c2 974 void Potion()
ThomasBGill 15:05a227f970c2 975 {
ThomasBGill 35:2c290fa78f1d 976 //Generates what the potion is
ThomasBGill 21:aa4feee6aa39 977 int p = rand() % 5; //0- Poison, 1- Teleport, Else- Full heal
ThomasBGill 15:05a227f970c2 978
ThomasBGill 15:05a227f970c2 979 lcd.clear();
ThomasBGill 15:05a227f970c2 980 lcd.printString("You find a", 0, 0);
ThomasBGill 16:a26d7519830e 981 lcd.printString("potion inside", 0, 1);
ThomasBGill 16:a26d7519830e 982 lcd.printString("the chest", 0, 2);
ThomasBGill 15:05a227f970c2 983 lcd.printString("Drink (Action)", 0, 4);
ThomasBGill 33:4fc26476b2e0 984 lcd.printString("Leave (Start)", 0, 5);
ThomasBGill 15:05a227f970c2 985 lcd.refresh();
ThomasBGill 15:05a227f970c2 986 wait(1.0);
ThomasBGill 15:05a227f970c2 987 Sleep();
ThomasBGill 15:05a227f970c2 988
ThomasBGill 21:aa4feee6aa39 989 if (ActFlag) { //Potion drunk
ThomasBGill 15:05a227f970c2 990 ActFlag = 0;
ThomasBGill 15:05a227f970c2 991
ThomasBGill 21:aa4feee6aa39 992 if (p == 0) { //Poison
ThomasBGill 15:05a227f970c2 993
ThomasBGill 21:aa4feee6aa39 994 int damage = rand() % 4 + 1;
ThomasBGill 15:05a227f970c2 995
ThomasBGill 15:05a227f970c2 996 ph = ph - damage;
ThomasBGill 15:05a227f970c2 997
ThomasBGill 15:05a227f970c2 998 char buffer[15];
ThomasBGill 15:05a227f970c2 999 int write = sprintf(buffer, "%d damage", damage);
ThomasBGill 13:2195ec8bc9ff 1000
ThomasBGill 13:2195ec8bc9ff 1001 lcd.clear();
ThomasBGill 15:05a227f970c2 1002 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 1003 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 1004 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 1005 lcd.printString("ill.", 0, 3);
ThomasBGill 15:05a227f970c2 1006 lcd.printString("You take", 0, 4);
ThomasBGill 15:05a227f970c2 1007 lcd.printString(buffer, 0, 5);
ThomasBGill 13:2195ec8bc9ff 1008 lcd.refresh();
ThomasBGill 15:05a227f970c2 1009 wait(1.0);
ThomasBGill 15:05a227f970c2 1010 Sleep();
ThomasBGill 15:05a227f970c2 1011
ThomasBGill 15:05a227f970c2 1012 //Check if player is dead
ThomasBGill 21:aa4feee6aa39 1013 if (ph < 0) {
ThomasBGill 15:05a227f970c2 1014 GameOver();
ThomasBGill 15:05a227f970c2 1015 }
ThomasBGill 22:dae750e4d749 1016 } else if (p == 1) { //Teleport
ThomasBGill 12:30a242706847 1017
ThomasBGill 15:05a227f970c2 1018 lcd.clear();
ThomasBGill 15:05a227f970c2 1019 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 1020 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 1021 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 1022 lcd.printString("your body", 0, 3);
ThomasBGill 15:05a227f970c2 1023 lcd.printString("being", 0, 4);
ThomasBGill 15:05a227f970c2 1024 lcd.printString("transported", 0, 5);
ThomasBGill 15:05a227f970c2 1025 lcd.refresh();
ThomasBGill 15:05a227f970c2 1026 wait(1.0);
ThomasBGill 15:05a227f970c2 1027 Sleep();
ThomasBGill 15:05a227f970c2 1028
ThomasBGill 15:05a227f970c2 1029 GameLoop();
ThomasBGill 15:05a227f970c2 1030
ThomasBGill 22:dae750e4d749 1031 } else { //Full heal
ThomasBGill 15:05a227f970c2 1032
ThomasBGill 29:89bc8c8aa8ac 1033 ph = PH_MAX;
ThomasBGill 13:2195ec8bc9ff 1034
ThomasBGill 13:2195ec8bc9ff 1035 lcd.clear();
ThomasBGill 15:05a227f970c2 1036 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 1037 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 1038 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 1039 lcd.printString("all your", 0, 3);
ThomasBGill 15:05a227f970c2 1040 lcd.printString("wounds heal", 0, 4);
ThomasBGill 13:2195ec8bc9ff 1041 lcd.refresh();
ThomasBGill 15:05a227f970c2 1042 wait(1.0);
ThomasBGill 15:05a227f970c2 1043 Sleep();
ThomasBGill 13:2195ec8bc9ff 1044 }
ThomasBGill 33:4fc26476b2e0 1045 }
ThomasBGill 33:4fc26476b2e0 1046 if(StartFlag) { //Leave the potion
ThomasBGill 15:05a227f970c2 1047 StartFlag = 0;
ThomasBGill 15:05a227f970c2 1048 lcd.clear();
ThomasBGill 15:05a227f970c2 1049 lcd.printString("You walk away", 0, 0);
ThomasBGill 15:05a227f970c2 1050 lcd.printString("and leave the", 0, 1);
ThomasBGill 15:05a227f970c2 1051 lcd.printString("potion", 0, 2);
ThomasBGill 15:05a227f970c2 1052 lcd.refresh();
ThomasBGill 15:05a227f970c2 1053 wait(1.0);
ThomasBGill 15:05a227f970c2 1054 Sleep();
ThomasBGill 15:05a227f970c2 1055 }
ThomasBGill 15:05a227f970c2 1056 }
ThomasBGill 13:2195ec8bc9ff 1057
ThomasBGill 21:aa4feee6aa39 1058 void GameOver()
ThomasBGill 10:59c874d006ab 1059 {
ThomasBGill 21:aa4feee6aa39 1060 lcd.inverseMode();
ThomasBGill 21:aa4feee6aa39 1061 lcd.clear();
ThomasBGill 21:aa4feee6aa39 1062 lcd.printString("GAME OVER", 12, 2);
ThomasBGill 21:aa4feee6aa39 1063 lcd.refresh();
ThomasBGill 21:aa4feee6aa39 1064 wait(1.0);
ThomasBGill 21:aa4feee6aa39 1065 Sleep();
ThomasBGill 21:aa4feee6aa39 1066 lcd.normalMode();
ThomasBGill 23:1b8b1d043403 1067 ScoreScreen();
ThomasBGill 23:1b8b1d043403 1068 }
ThomasBGill 23:1b8b1d043403 1069
ThomasBGill 23:1b8b1d043403 1070 void ScoreScreen()
ThomasBGill 23:1b8b1d043403 1071 {
ThomasBGill 23:1b8b1d043403 1072 char buffer[14];
ThomasBGill 23:1b8b1d043403 1073
ThomasBGill 23:1b8b1d043403 1074 int write = sprintf(buffer, "%d points", score);
ThomasBGill 23:1b8b1d043403 1075
ThomasBGill 23:1b8b1d043403 1076 lcd.clear();
ThomasBGill 23:1b8b1d043403 1077 lcd.printString("You scored", 6, 1);
ThomasBGill 35:2c290fa78f1d 1078 lcd.printString(buffer, 6, 2); //Player's final score
ThomasBGill 23:1b8b1d043403 1079 lcd.refresh();
ThomasBGill 23:1b8b1d043403 1080 wait(1.0);
ThomasBGill 23:1b8b1d043403 1081 Sleep();
ThomasBGill 23:1b8b1d043403 1082
ThomasBGill 23:1b8b1d043403 1083 HighScoreScreen();
ThomasBGill 21:aa4feee6aa39 1084 }
ThomasBGill 10:59c874d006ab 1085
ThomasBGill 23:1b8b1d043403 1086 void HighScoreScreen()
ThomasBGill 23:1b8b1d043403 1087 {
ThomasBGill 23:1b8b1d043403 1088 HighScoreCheck();
ThomasBGill 23:1b8b1d043403 1089
ThomasBGill 23:1b8b1d043403 1090 char buffer1[14];
ThomasBGill 23:1b8b1d043403 1091 int write = sprintf(buffer1, "1. %d", HScore1);
ThomasBGill 23:1b8b1d043403 1092
ThomasBGill 23:1b8b1d043403 1093 char buffer2[14];
ThomasBGill 23:1b8b1d043403 1094 write = sprintf(buffer2, "2. %d", HScore2);
ThomasBGill 23:1b8b1d043403 1095
ThomasBGill 23:1b8b1d043403 1096 char buffer3[14];
ThomasBGill 23:1b8b1d043403 1097 write = sprintf(buffer3, "3. %d", HScore3);
ThomasBGill 23:1b8b1d043403 1098
ThomasBGill 24:4c4467971c91 1099 char buffer4[14];
ThomasBGill 24:4c4467971c91 1100 write = sprintf(buffer4, "4. %d", HScore4);
ThomasBGill 24:4c4467971c91 1101
ThomasBGill 23:1b8b1d043403 1102 lcd.clear();
ThomasBGill 23:1b8b1d043403 1103 lcd.printString("High Scores", 6, 0);
ThomasBGill 35:2c290fa78f1d 1104 lcd.printString(buffer1, 6, 2); //High score 1
ThomasBGill 35:2c290fa78f1d 1105 lcd.printString(buffer2, 6, 3); //High score 2
ThomasBGill 35:2c290fa78f1d 1106 lcd.printString(buffer3, 6, 4); //High score 3
ThomasBGill 35:2c290fa78f1d 1107 lcd.printString(buffer4, 6, 5); //High score 4
ThomasBGill 23:1b8b1d043403 1108 lcd.refresh();
ThomasBGill 23:1b8b1d043403 1109 wait(1.0);
ThomasBGill 32:99ca304085e6 1110
ThomasBGill 32:99ca304085e6 1111 while(1) {
ThomasBGill 32:99ca304085e6 1112 Sleep();
ThomasBGill 23:1b8b1d043403 1113
ThomasBGill 33:4fc26476b2e0 1114 if(StartFlag) {
ThomasBGill 33:4fc26476b2e0 1115 StartFlag = 0;
ThomasBGill 33:4fc26476b2e0 1116 MainMenu();
ThomasBGill 33:4fc26476b2e0 1117 }
ThomasBGill 32:99ca304085e6 1118 if(ActFlag) {
ThomasBGill 32:99ca304085e6 1119 ActFlag = 0;
ThomasBGill 32:99ca304085e6 1120 }
ThomasBGill 32:99ca304085e6 1121 }
ThomasBGill 21:aa4feee6aa39 1122 }