Thomas Gill / Mbed 2 deprecated LabyrinthOfTheMinotaur

Dependencies:   N5110 PowerControl mbed

Committer:
ThomasBGill
Date:
Mon May 04 16:26:43 2015 +0000
Revision:
20:e54792b89571
Parent:
19:1ab2d83ebffa
Child:
21:aa4feee6aa39
Worldbuilder functions put into separate header and source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasBGill 0:9200b3c387ed 1 #include "N5110.h"
ThomasBGill 1:0f774d41584c 2 #include "PowerControl/PowerControl.h"
ThomasBGill 1:0f774d41584c 3 #include "PowerControl/EthernetPowerControl.h"
ThomasBGill 20:e54792b89571 4 #include "WorldBuilder.h"
ThomasBGill 0:9200b3c387ed 5
ThomasBGill 0:9200b3c387ed 6 // vcc sce rst dc mosi clk led
ThomasBGill 0:9200b3c387ed 7 N5110 lcd (p5, p6, p7, p8, p11, p13, p21);
ThomasBGill 0:9200b3c387ed 8 InterruptIn Act (p22);
ThomasBGill 0:9200b3c387ed 9 InterruptIn Start (p23);
ThomasBGill 0:9200b3c387ed 10 InterruptIn Up (p24);
ThomasBGill 0:9200b3c387ed 11 InterruptIn Down (p25);
ThomasBGill 0:9200b3c387ed 12 InterruptIn Left (p26);
ThomasBGill 0:9200b3c387ed 13 InterruptIn Right (p27);
ThomasBGill 0:9200b3c387ed 14 AnalogIn Noise (p19);
ThomasBGill 0:9200b3c387ed 15
ThomasBGill 1:0f774d41584c 16 #define USR_POWERDOWN (0x104)
ThomasBGill 1:0f774d41584c 17
ThomasBGill 8:ee857f0147aa 18 struct TILES {
ThomasBGill 7:cd799c701997 19 char Symbol; // Symbol for this tile
ThomasBGill 7:cd799c701997 20 bool Passable; // Can tile be walked on
ThomasBGill 7:cd799c701997 21 };
ThomasBGill 7:cd799c701997 22
ThomasBGill 8:ee857f0147aa 23 TILES TileList[] = {
ThomasBGill 7:cd799c701997 24 { '#', false }, // 0- WALL
ThomasBGill 7:cd799c701997 25 { '.', true}, // 1- FLOOR
ThomasBGill 7:cd799c701997 26 { '+', true }, // 2- ENTER
ThomasBGill 7:cd799c701997 27 { 'x', true }, // 3- EXIT
ThomasBGill 11:b86a15d26de9 28 { '.', true}, // 4- FLOOR_SEEN
ThomasBGill 12:30a242706847 29 { '=', true}, // 5- CHEST
ThomasBGill 12:30a242706847 30 { '/', true}, // 6- CHEST_OPENED
ThomasBGill 12:30a242706847 31 };
ThomasBGill 12:30a242706847 32
ThomasBGill 12:30a242706847 33 struct ITEMS {
ThomasBGill 13:2195ec8bc9ff 34 char ItemName[15]; //Item name
ThomasBGill 13:2195ec8bc9ff 35 int ItemValue; //Damage/ armour value
ThomasBGill 12:30a242706847 36 };
ThomasBGill 12:30a242706847 37
ThomasBGill 12:30a242706847 38 ITEMS ItemList[] = {
ThomasBGill 13:2195ec8bc9ff 39 //Weapons
ThomasBGill 16:a26d7519830e 40 { "Dagger", 4}, //0
ThomasBGill 13:2195ec8bc9ff 41 { "Axe", 5}, //1
ThomasBGill 13:2195ec8bc9ff 42 { "Mace", 6}, //2
ThomasBGill 13:2195ec8bc9ff 43 { "Sword", 7}, //3
ThomasBGill 13:2195ec8bc9ff 44 { "Warhammer", 10}, //4
ThomasBGill 13:2195ec8bc9ff 45 //Armour
ThomasBGill 18:98ea2b787894 46 { "Cloth armour", 1}, //5
ThomasBGill 13:2195ec8bc9ff 47 { "Leather armour", 2}, //6
ThomasBGill 18:98ea2b787894 48 { "Studded armour", 3}, //7
ThomasBGill 18:98ea2b787894 49 { "Chainmail vest", 4}, //8
ThomasBGill 18:98ea2b787894 50 { "Plate armour", 5}, //9
ThomasBGill 7:cd799c701997 51 };
ThomasBGill 7:cd799c701997 52
ThomasBGill 13:2195ec8bc9ff 53 struct ENEMIES {
ThomasBGill 17:8790dd599b25 54 char EName[9]; //Enemy name
ThomasBGill 13:2195ec8bc9ff 55 int EHealth; //Enemy health
ThomasBGill 13:2195ec8bc9ff 56 int EDamage; //Enemy damage
ThomasBGill 13:2195ec8bc9ff 57 int EArmour; //Enemy armour
ThomasBGill 13:2195ec8bc9ff 58 int EDodge; //Enemy dodge chance
ThomasBGill 13:2195ec8bc9ff 59 int EHit; //Enemy hit chance
ThomasBGill 16:a26d7519830e 60 int ESpd; //Enemy speed (use for running away during fights)
ThomasBGill 13:2195ec8bc9ff 61 };
ThomasBGill 13:2195ec8bc9ff 62
ThomasBGill 13:2195ec8bc9ff 63 ENEMIES EnemyList[] = {
ThomasBGill 17:8790dd599b25 64 //Name HP Dmg Arm Dg Ht Spd
ThomasBGill 17:8790dd599b25 65 {"Huge Rat", 5, 3, 0, 25, 70, 40}, //0- Huge Rat
ThomasBGill 17:8790dd599b25 66 {"Goblin", 6, 3, 2, 25, 60, 30}, //1- Goblin
ThomasBGill 17:8790dd599b25 67 {"Skeleton", 8, 5, 3, 10, 50, 10}, //2- Skeleton
ThomasBGill 17:8790dd599b25 68 {"Wraith", 5, 4, 0, 40, 60, 50}, //3- Wraith
ThomasBGill 17:8790dd599b25 69 {"Ogre", 10, 7, 3, 10, 35, 15}, //4- Ogre
ThomasBGill 17:8790dd599b25 70 {"Minotaur", 15, 8, 5, 20, 45, 100}, //5- Minotaur
ThomasBGill 13:2195ec8bc9ff 71 };
ThomasBGill 7:cd799c701997 72
ThomasBGill 0:9200b3c387ed 73 //Variables
ThomasBGill 9:3cad581b5419 74 int ActFlag = 0;
ThomasBGill 9:3cad581b5419 75 int StartFlag = 0;
ThomasBGill 10:59c874d006ab 76 int DirFlag = 0;
ThomasBGill 0:9200b3c387ed 77
ThomasBGill 7:cd799c701997 78 //Space type player is on
ThomasBGill 7:cd799c701997 79 int pSpace;
ThomasBGill 7:cd799c701997 80
ThomasBGill 7:cd799c701997 81 //Player coordinates
ThomasBGill 7:cd799c701997 82 int px;
ThomasBGill 7:cd799c701997 83 int py;
ThomasBGill 2:0b0311609edc 84
ThomasBGill 13:2195ec8bc9ff 85 //Player Health
ThomasBGill 13:2195ec8bc9ff 86 int ph = 15;
ThomasBGill 13:2195ec8bc9ff 87
ThomasBGill 13:2195ec8bc9ff 88 //Player weapon
ThomasBGill 13:2195ec8bc9ff 89 int pw = 0; //0 to 4
ThomasBGill 13:2195ec8bc9ff 90
ThomasBGill 13:2195ec8bc9ff 91 //Player armour
ThomasBGill 13:2195ec8bc9ff 92 int pa = 5; //5 to 9
ThomasBGill 13:2195ec8bc9ff 93
ThomasBGill 1:0f774d41584c 94 //Power Saving
ThomasBGill 1:0f774d41584c 95 int semihost_powerdown()
ThomasBGill 1:0f774d41584c 96 {
ThomasBGill 1:0f774d41584c 97 uint32_t arg;
ThomasBGill 1:0f774d41584c 98 return __semihost(USR_POWERDOWN, &arg);
ThomasBGill 1:0f774d41584c 99 }
ThomasBGill 1:0f774d41584c 100
ThomasBGill 0:9200b3c387ed 101 //ISR
ThomasBGill 0:9200b3c387ed 102 void ActPressed()
ThomasBGill 0:9200b3c387ed 103 {
ThomasBGill 9:3cad581b5419 104 ActFlag = 1;
ThomasBGill 0:9200b3c387ed 105 }
ThomasBGill 0:9200b3c387ed 106 void StartPressed()
ThomasBGill 0:9200b3c387ed 107 {
ThomasBGill 9:3cad581b5419 108 StartFlag = 1;
ThomasBGill 0:9200b3c387ed 109 }
ThomasBGill 10:59c874d006ab 110 void DirPressed()
ThomasBGill 0:9200b3c387ed 111 {
ThomasBGill 13:2195ec8bc9ff 112 DirFlag = 1;
ThomasBGill 13:2195ec8bc9ff 113 }
ThomasBGill 10:59c874d006ab 114
ThomasBGill 13:2195ec8bc9ff 115 //Voids
ThomasBGill 13:2195ec8bc9ff 116 void MainMenu();
ThomasBGill 15:05a227f970c2 117 void GameLoop();
ThomasBGill 0:9200b3c387ed 118
ThomasBGill 9:3cad581b5419 119 void FlashPlayerLocation()
ThomasBGill 9:3cad581b5419 120 {
ThomasBGill 9:3cad581b5419 121 lcd.setPixel(px,py);
ThomasBGill 9:3cad581b5419 122 lcd.refresh();
ThomasBGill 9:3cad581b5419 123 wait(0.5);
ThomasBGill 9:3cad581b5419 124 lcd.clearPixel(px,py);
ThomasBGill 9:3cad581b5419 125 lcd.refresh();
ThomasBGill 9:3cad581b5419 126 wait(0.5);
ThomasBGill 13:2195ec8bc9ff 127 }
ThomasBGill 9:3cad581b5419 128
ThomasBGill 9:3cad581b5419 129
ThomasBGill 1:0f774d41584c 130 void DrawMap()
ThomasBGill 1:0f774d41584c 131 {
ThomasBGill 1:0f774d41584c 132 //Draw map on screen
ThomasBGill 1:0f774d41584c 133 for(int i=0; i<84; i++) {
ThomasBGill 1:0f774d41584c 134 for (int j=0; j<48; j++) {
ThomasBGill 12:30a242706847 135 if(map[i][j] == FLOOR_SEEN || map[i][j] == CHEST_OPENED) {
ThomasBGill 1:0f774d41584c 136 lcd.clearPixel(i, j);
ThomasBGill 1:0f774d41584c 137 } else {
ThomasBGill 1:0f774d41584c 138 lcd.setPixel(i, j);
ThomasBGill 1:0f774d41584c 139 }
ThomasBGill 1:0f774d41584c 140 }
ThomasBGill 1:0f774d41584c 141 }
ThomasBGill 1:0f774d41584c 142 lcd.refresh();
ThomasBGill 20:e54792b89571 143 }
ThomasBGill 2:0b0311609edc 144
ThomasBGill 2:0b0311609edc 145 void World()
ThomasBGill 2:0b0311609edc 146 {
ThomasBGill 2:0b0311609edc 147 Walls();
ThomasBGill 12:30a242706847 148 if(level == 5) {
ThomasBGill 12:30a242706847 149 LabyrinthBuilder();
ThomasBGill 12:30a242706847 150 } else {
ThomasBGill 12:30a242706847 151 DungeonBuilder();
ThomasBGill 20:e54792b89571 152 //LabyrinthBuilder();
ThomasBGill 12:30a242706847 153 }
ThomasBGill 6:ca5db4353c95 154
ThomasBGill 8:ee857f0147aa 155 px = enx;
ThomasBGill 8:ee857f0147aa 156 py = eny;
ThomasBGill 8:ee857f0147aa 157
ThomasBGill 8:ee857f0147aa 158 wait(1.0);
ThomasBGill 0:9200b3c387ed 159 }
ThomasBGill 0:9200b3c387ed 160
ThomasBGill 8:ee857f0147aa 161 void PlayerCamera()
ThomasBGill 8:ee857f0147aa 162 {
ThomasBGill 8:ee857f0147aa 163 lcd.clear();
ThomasBGill 8:ee857f0147aa 164
ThomasBGill 8:ee857f0147aa 165 int tile;
ThomasBGill 8:ee857f0147aa 166
ThomasBGill 8:ee857f0147aa 167 for(int i = 0; i < 14; i++) {
ThomasBGill 8:ee857f0147aa 168 for(int j = 0; j < 6; j++) {
ThomasBGill 8:ee857f0147aa 169
ThomasBGill 8:ee857f0147aa 170 if(i == 6 && j == 2) {
ThomasBGill 8:ee857f0147aa 171 lcd.printString("@", (6*i)+1, j);
ThomasBGill 8:ee857f0147aa 172 } else {
ThomasBGill 8:ee857f0147aa 173 int diffx = i - 6;
ThomasBGill 8:ee857f0147aa 174 int diffy = j - 2;
ThomasBGill 8:ee857f0147aa 175
ThomasBGill 9:3cad581b5419 176 if(px+diffx < 84 && px+diffx > 0 && py+diffy < 48 && py+diffy > 0) {
ThomasBGill 9:3cad581b5419 177 tile = map[px+diffx][py+diffy];
ThomasBGill 9:3cad581b5419 178 } else {
ThomasBGill 9:3cad581b5419 179 tile = WALL;
ThomasBGill 9:3cad581b5419 180 }
ThomasBGill 8:ee857f0147aa 181 lcd.printChar(TileList[tile].Symbol, (6*i)+1, j);
ThomasBGill 11:b86a15d26de9 182
ThomasBGill 11:b86a15d26de9 183 if(map[px+diffx][py+diffy] == FLOOR) {
ThomasBGill 11:b86a15d26de9 184 map[px+diffx][py+diffy] = FLOOR_SEEN;
ThomasBGill 11:b86a15d26de9 185 }
ThomasBGill 11:b86a15d26de9 186
ThomasBGill 8:ee857f0147aa 187 }
ThomasBGill 8:ee857f0147aa 188 }
ThomasBGill 8:ee857f0147aa 189 }
ThomasBGill 8:ee857f0147aa 190 lcd.refresh();
ThomasBGill 8:ee857f0147aa 191 }
ThomasBGill 8:ee857f0147aa 192
ThomasBGill 8:ee857f0147aa 193 void PlayerMove()
ThomasBGill 8:ee857f0147aa 194 {
ThomasBGill 8:ee857f0147aa 195 if(Up) {
ThomasBGill 8:ee857f0147aa 196 int tile = map[px][py-1];
ThomasBGill 8:ee857f0147aa 197 if(TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 198 py--;
ThomasBGill 8:ee857f0147aa 199 }
ThomasBGill 8:ee857f0147aa 200 }
ThomasBGill 8:ee857f0147aa 201 if(Down) {
ThomasBGill 8:ee857f0147aa 202 int tile = map[px][py+1];
ThomasBGill 8:ee857f0147aa 203 if(TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 204 py++;
ThomasBGill 8:ee857f0147aa 205 }
ThomasBGill 8:ee857f0147aa 206 }
ThomasBGill 8:ee857f0147aa 207 if(Right) {
ThomasBGill 8:ee857f0147aa 208 int tile = map[px+1][py];
ThomasBGill 8:ee857f0147aa 209 if(TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 210 px++;
ThomasBGill 8:ee857f0147aa 211 }
ThomasBGill 8:ee857f0147aa 212 }
ThomasBGill 8:ee857f0147aa 213 if(Left) {
ThomasBGill 8:ee857f0147aa 214 int tile = map[px-1][py];
ThomasBGill 8:ee857f0147aa 215 if(TileList[tile].Passable) {
ThomasBGill 8:ee857f0147aa 216 px--;
ThomasBGill 8:ee857f0147aa 217 }
ThomasBGill 8:ee857f0147aa 218 }
ThomasBGill 13:2195ec8bc9ff 219 }
ThomasBGill 13:2195ec8bc9ff 220
ThomasBGill 15:05a227f970c2 221 void GameOver()
ThomasBGill 15:05a227f970c2 222 {
ThomasBGill 16:a26d7519830e 223 lcd.inverseMode();
ThomasBGill 15:05a227f970c2 224 lcd.clear();
ThomasBGill 15:05a227f970c2 225 lcd.printString("GAME OVER", 12, 2);
ThomasBGill 15:05a227f970c2 226 lcd.refresh();
ThomasBGill 15:05a227f970c2 227 wait(1.0);
ThomasBGill 15:05a227f970c2 228 Sleep();
ThomasBGill 16:a26d7519830e 229 lcd.normalMode();
ThomasBGill 15:05a227f970c2 230 MainMenu();
ThomasBGill 15:05a227f970c2 231 }
ThomasBGill 15:05a227f970c2 232
ThomasBGill 16:a26d7519830e 233 void MonsterAttack(int m)
ThomasBGill 16:a26d7519830e 234 {
ThomasBGill 16:a26d7519830e 235 if(rand()%100 + 1 < EnemyList[m].EHit) { //If monster hits and isn't dead
ThomasBGill 16:a26d7519830e 236
ThomasBGill 16:a26d7519830e 237 int damage = EnemyList[m].EDamage - ItemList[pa].ItemValue + rand()%3 - rand()%3; //Calculate damage
ThomasBGill 16:a26d7519830e 238 if (damage < 0) {
ThomasBGill 16:a26d7519830e 239 damage = 0;
ThomasBGill 16:a26d7519830e 240 }
ThomasBGill 16:a26d7519830e 241 ph = ph - damage; //Apply damage and calculate the monster's health
ThomasBGill 16:a26d7519830e 242
ThomasBGill 16:a26d7519830e 243 char buffer[14];
ThomasBGill 16:a26d7519830e 244 int write = sprintf(buffer,"%d damage",damage); // print formatted data to buffer
ThomasBGill 16:a26d7519830e 245
ThomasBGill 16:a26d7519830e 246 lcd.clear();
ThomasBGill 16:a26d7519830e 247 lcd.printString(EnemyList[m].EName, 0 ,1);
ThomasBGill 16:a26d7519830e 248 lcd.printString("hits you for", 0 , 2);
ThomasBGill 16:a26d7519830e 249 lcd.printString(buffer, 0 , 3);
ThomasBGill 16:a26d7519830e 250 lcd.refresh();
ThomasBGill 16:a26d7519830e 251 wait(1.0);
ThomasBGill 16:a26d7519830e 252 Sleep();
ThomasBGill 16:a26d7519830e 253
ThomasBGill 16:a26d7519830e 254 } else { //You dodge
ThomasBGill 16:a26d7519830e 255 lcd.clear();
ThomasBGill 16:a26d7519830e 256 lcd.printString("You dodge the", 0 ,1);
ThomasBGill 16:a26d7519830e 257 lcd.printString("monster's", 0 , 2);
ThomasBGill 16:a26d7519830e 258 lcd.printString("attack", 0 , 3);
ThomasBGill 16:a26d7519830e 259 lcd.refresh();
ThomasBGill 16:a26d7519830e 260 wait(1.0);
ThomasBGill 16:a26d7519830e 261 Sleep();
ThomasBGill 16:a26d7519830e 262 }
ThomasBGill 16:a26d7519830e 263 if(ph <= 0) { //Check if player is dead
ThomasBGill 16:a26d7519830e 264 GameOver();
ThomasBGill 16:a26d7519830e 265 }
ThomasBGill 16:a26d7519830e 266
ThomasBGill 16:a26d7519830e 267 }
ThomasBGill 16:a26d7519830e 268
ThomasBGill 13:2195ec8bc9ff 269 void Fight()
ThomasBGill 13:2195ec8bc9ff 270 {
ThomasBGill 18:98ea2b787894 271 int m = rand()%(level+1);
ThomasBGill 13:2195ec8bc9ff 272
ThomasBGill 13:2195ec8bc9ff 273 int mh = EnemyList[m].EHealth;
ThomasBGill 13:2195ec8bc9ff 274
ThomasBGill 13:2195ec8bc9ff 275 lcd.clear();
ThomasBGill 13:2195ec8bc9ff 276 lcd.printString("FIGHT!", 24, 2);
ThomasBGill 13:2195ec8bc9ff 277
ThomasBGill 13:2195ec8bc9ff 278 for(int i = 0; i<5; i++) {
ThomasBGill 13:2195ec8bc9ff 279 lcd.inverseMode();
ThomasBGill 13:2195ec8bc9ff 280 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 281 wait(0.2);
ThomasBGill 13:2195ec8bc9ff 282 lcd.normalMode();
ThomasBGill 13:2195ec8bc9ff 283 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 284 wait(0.2);
ThomasBGill 13:2195ec8bc9ff 285 }
ThomasBGill 13:2195ec8bc9ff 286
ThomasBGill 13:2195ec8bc9ff 287 bool menu = 1;
ThomasBGill 13:2195ec8bc9ff 288
ThomasBGill 13:2195ec8bc9ff 289 while(1) {
ThomasBGill 13:2195ec8bc9ff 290 ActFlag = 0;
ThomasBGill 13:2195ec8bc9ff 291 StartFlag = 0;
ThomasBGill 13:2195ec8bc9ff 292 DirFlag = 0;
ThomasBGill 13:2195ec8bc9ff 293
ThomasBGill 13:2195ec8bc9ff 294 lcd.clear();
ThomasBGill 13:2195ec8bc9ff 295
ThomasBGill 13:2195ec8bc9ff 296 lcd.printString(EnemyList[m].EName, 0, 0);
ThomasBGill 13:2195ec8bc9ff 297 char buffer1[14];
ThomasBGill 13:2195ec8bc9ff 298 int write = sprintf(buffer1,"%d/%d",mh, EnemyList[m].EHealth); // print formatted data to buffer
ThomasBGill 13:2195ec8bc9ff 299 lcd.printString(buffer1, 54, 0);
ThomasBGill 13:2195ec8bc9ff 300
ThomasBGill 13:2195ec8bc9ff 301 lcd.printString("You", 0, 2);
ThomasBGill 13:2195ec8bc9ff 302 char buffer2[14];
ThomasBGill 13:2195ec8bc9ff 303 write = sprintf(buffer2,"%d/15",ph); // print formatted data to buffer
ThomasBGill 13:2195ec8bc9ff 304 lcd.printString(buffer2, 54, 2);
ThomasBGill 13:2195ec8bc9ff 305
ThomasBGill 13:2195ec8bc9ff 306 if(menu) {
ThomasBGill 13:2195ec8bc9ff 307 lcd.printString("Fight <", 0, 4);
ThomasBGill 13:2195ec8bc9ff 308 lcd.printString("Run", 0, 5);
ThomasBGill 13:2195ec8bc9ff 309 } else {
ThomasBGill 13:2195ec8bc9ff 310 lcd.printString("Fight", 0, 4);
ThomasBGill 13:2195ec8bc9ff 311 lcd.printString("Run <", 0, 5);
ThomasBGill 13:2195ec8bc9ff 312 }
ThomasBGill 13:2195ec8bc9ff 313 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 314 Sleep();
ThomasBGill 13:2195ec8bc9ff 315
ThomasBGill 13:2195ec8bc9ff 316 if(DirFlag) {
ThomasBGill 13:2195ec8bc9ff 317 DirFlag = 0;
ThomasBGill 13:2195ec8bc9ff 318 menu = !menu;
ThomasBGill 13:2195ec8bc9ff 319 }
ThomasBGill 13:2195ec8bc9ff 320 if(ActFlag) {
ThomasBGill 13:2195ec8bc9ff 321 ActFlag = 0;
ThomasBGill 13:2195ec8bc9ff 322 if(menu) { //Fight
ThomasBGill 13:2195ec8bc9ff 323 //Hit monster
ThomasBGill 13:2195ec8bc9ff 324 if(rand()%100 + 1 > EnemyList[m].EDodge) { //If monster doesn't dodge
ThomasBGill 13:2195ec8bc9ff 325
ThomasBGill 13:2195ec8bc9ff 326 int damage = ItemList[pw].ItemValue - EnemyList[m].EArmour + rand()%3 - rand()%3; //Calculate damage
ThomasBGill 15:05a227f970c2 327 if (damage < 0) {
ThomasBGill 15:05a227f970c2 328 damage = 0;
ThomasBGill 13:2195ec8bc9ff 329 }
ThomasBGill 15:05a227f970c2 330 mh = mh - damage; //Apply damage and calculate the monster's health
ThomasBGill 15:05a227f970c2 331
ThomasBGill 15:05a227f970c2 332 char buffer3[14];
ThomasBGill 15:05a227f970c2 333 write = sprintf(buffer3,"for %d damage",damage); // print formatted data to buffer
ThomasBGill 15:05a227f970c2 334
ThomasBGill 15:05a227f970c2 335 lcd.clear();
ThomasBGill 16:a26d7519830e 336 lcd.printString("You hit the", 0 , 1);
ThomasBGill 16:a26d7519830e 337 lcd.printString(EnemyList[m].EName, 0 ,2);
ThomasBGill 16:a26d7519830e 338 lcd.printString(buffer3, 0, 3);
ThomasBGill 15:05a227f970c2 339 lcd.refresh();
ThomasBGill 15:05a227f970c2 340 wait(1.0);
ThomasBGill 15:05a227f970c2 341 Sleep();
ThomasBGill 15:05a227f970c2 342
ThomasBGill 15:05a227f970c2 343 } else { //Monster dodges
ThomasBGill 15:05a227f970c2 344 lcd.clear();
ThomasBGill 16:a26d7519830e 345 lcd.printString(EnemyList[m].EName, 0 ,1);
ThomasBGill 16:a26d7519830e 346 lcd.printString("dodges your", 0 , 2);
ThomasBGill 16:a26d7519830e 347 lcd.printString("attack", 0 , 3);
ThomasBGill 15:05a227f970c2 348 lcd.refresh();
ThomasBGill 15:05a227f970c2 349 wait(1.0);
ThomasBGill 15:05a227f970c2 350 Sleep();
ThomasBGill 13:2195ec8bc9ff 351 }
ThomasBGill 13:2195ec8bc9ff 352
ThomasBGill 16:a26d7519830e 353 if(mh <= 0) { //Check if monster is dead
ThomasBGill 13:2195ec8bc9ff 354 lcd.clear();
ThomasBGill 15:05a227f970c2 355 lcd.printString("You win!", 18, 2);
ThomasBGill 13:2195ec8bc9ff 356 lcd.refresh();
ThomasBGill 15:05a227f970c2 357 wait(1.0);
ThomasBGill 13:2195ec8bc9ff 358 Sleep();
ThomasBGill 13:2195ec8bc9ff 359 break;
ThomasBGill 13:2195ec8bc9ff 360 }
ThomasBGill 13:2195ec8bc9ff 361
ThomasBGill 16:a26d7519830e 362 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 363
ThomasBGill 13:2195ec8bc9ff 364
ThomasBGill 16:a26d7519830e 365 } else { //Run away
ThomasBGill 15:05a227f970c2 366
ThomasBGill 16:a26d7519830e 367 int b = rand()%5;
ThomasBGill 16:a26d7519830e 368
ThomasBGill 16:a26d7519830e 369 if(b == 0) { //Monster blocks the path
ThomasBGill 15:05a227f970c2 370
ThomasBGill 15:05a227f970c2 371 lcd.clear();
ThomasBGill 16:a26d7519830e 372 lcd.printString("You try to run", 0, 0);
ThomasBGill 16:a26d7519830e 373 lcd.printString("away but the", 0, 1);
ThomasBGill 16:a26d7519830e 374 lcd.printString("monster blocks", 0, 2);
ThomasBGill 16:a26d7519830e 375 lcd.printString("the path", 0, 3);
ThomasBGill 15:05a227f970c2 376 lcd.refresh();
ThomasBGill 15:05a227f970c2 377 wait(1.0);
ThomasBGill 15:05a227f970c2 378 Sleep();
ThomasBGill 15:05a227f970c2 379
ThomasBGill 16:a26d7519830e 380 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 381
ThomasBGill 16:a26d7519830e 382 } else {
ThomasBGill 16:a26d7519830e 383
ThomasBGill 16:a26d7519830e 384 int s = rand()%100 + 1;
ThomasBGill 16:a26d7519830e 385
ThomasBGill 16:a26d7519830e 386 if(s > EnemyList[m].ESpd) { //If you outspeed monster
ThomasBGill 16:a26d7519830e 387
ThomasBGill 16:a26d7519830e 388 lcd.clear();
ThomasBGill 16:a26d7519830e 389 lcd.printString("You run away", 6, 2);
ThomasBGill 16:a26d7519830e 390 lcd.refresh();
ThomasBGill 17:8790dd599b25 391 wait(1.0);
ThomasBGill 16:a26d7519830e 392 Sleep();
ThomasBGill 16:a26d7519830e 393 break;
ThomasBGill 16:a26d7519830e 394
ThomasBGill 16:a26d7519830e 395 } else {
ThomasBGill 16:a26d7519830e 396
ThomasBGill 16:a26d7519830e 397 lcd.clear();
ThomasBGill 16:a26d7519830e 398 lcd.printString("You try to run", 0, 0);
ThomasBGill 16:a26d7519830e 399 lcd.printString("away but the", 0, 1);
ThomasBGill 16:a26d7519830e 400 lcd.printString("monster", 0, 2);
ThomasBGill 16:a26d7519830e 401 lcd.printString("catches up to", 0, 3);
ThomasBGill 16:a26d7519830e 402 lcd.printString("you", 0, 4);
ThomasBGill 16:a26d7519830e 403 lcd.refresh();
ThomasBGill 16:a26d7519830e 404 wait(1.0);
ThomasBGill 16:a26d7519830e 405 Sleep();
ThomasBGill 16:a26d7519830e 406
ThomasBGill 16:a26d7519830e 407 MonsterAttack(m);
ThomasBGill 16:a26d7519830e 408
ThomasBGill 16:a26d7519830e 409 }
ThomasBGill 8:ee857f0147aa 410
ThomasBGill 9:3cad581b5419 411
ThomasBGill 16:a26d7519830e 412 }
ThomasBGill 13:2195ec8bc9ff 413 }
ThomasBGill 13:2195ec8bc9ff 414 }
ThomasBGill 13:2195ec8bc9ff 415 }
ThomasBGill 13:2195ec8bc9ff 416 }
ThomasBGill 13:2195ec8bc9ff 417
ThomasBGill 13:2195ec8bc9ff 418 void Map()
ThomasBGill 13:2195ec8bc9ff 419 {
ThomasBGill 13:2195ec8bc9ff 420 lcd.clear();
ThomasBGill 13:2195ec8bc9ff 421 DrawMap();
ThomasBGill 13:2195ec8bc9ff 422 while(!StartFlag) {
ThomasBGill 13:2195ec8bc9ff 423 FlashPlayerLocation();
ThomasBGill 13:2195ec8bc9ff 424 }
ThomasBGill 13:2195ec8bc9ff 425 StartFlag = 0;
ThomasBGill 14:55802ce40285 426 ActFlag = 0;
ThomasBGill 14:55802ce40285 427 DirFlag = 0;
ThomasBGill 13:2195ec8bc9ff 428 }
ThomasBGill 13:2195ec8bc9ff 429
ThomasBGill 13:2195ec8bc9ff 430
ThomasBGill 13:2195ec8bc9ff 431 void Inventory()
ThomasBGill 13:2195ec8bc9ff 432 {
ThomasBGill 13:2195ec8bc9ff 433 lcd.clear();
ThomasBGill 13:2195ec8bc9ff 434 lcd.printString("Armour:", 0, 0);
ThomasBGill 13:2195ec8bc9ff 435 lcd.printString(ItemList[pa].ItemName, 0, 1);
ThomasBGill 13:2195ec8bc9ff 436 char buffer1[14];
ThomasBGill 13:2195ec8bc9ff 437 int write = sprintf(buffer1,"+%d Armour", ItemList[pa].ItemValue); // print formatted data to buffer
ThomasBGill 13:2195ec8bc9ff 438 lcd.printString(buffer1, 0, 2);
ThomasBGill 13:2195ec8bc9ff 439
ThomasBGill 13:2195ec8bc9ff 440 lcd.printString("Weapon:", 0, 3);
ThomasBGill 13:2195ec8bc9ff 441 lcd.printString(ItemList[pw].ItemName, 0, 4);
ThomasBGill 13:2195ec8bc9ff 442 char buffer2[14];
ThomasBGill 13:2195ec8bc9ff 443 write = sprintf(buffer2,"+%d Damage", ItemList[pw].ItemValue); // print formatted data to buffer
ThomasBGill 13:2195ec8bc9ff 444 lcd.printString(buffer2, 0, 5);
ThomasBGill 13:2195ec8bc9ff 445 lcd.refresh();
ThomasBGill 14:55802ce40285 446
ThomasBGill 14:55802ce40285 447 while(1) {
ThomasBGill 14:55802ce40285 448 Sleep();
ThomasBGill 14:55802ce40285 449
ThomasBGill 14:55802ce40285 450 if(ActFlag) {
ThomasBGill 14:55802ce40285 451 ActFlag = 0;
ThomasBGill 14:55802ce40285 452 }
ThomasBGill 14:55802ce40285 453 if(DirFlag) {
ThomasBGill 14:55802ce40285 454 DirFlag = 0;
ThomasBGill 14:55802ce40285 455 break;
ThomasBGill 14:55802ce40285 456 }
ThomasBGill 14:55802ce40285 457 if(StartFlag) {
ThomasBGill 14:55802ce40285 458 StartFlag = 0;
ThomasBGill 14:55802ce40285 459 break;
ThomasBGill 14:55802ce40285 460 }
ThomasBGill 14:55802ce40285 461 }
ThomasBGill 14:55802ce40285 462 }
ThomasBGill 14:55802ce40285 463
ThomasBGill 14:55802ce40285 464 void MapLegend()
ThomasBGill 14:55802ce40285 465 {
ThomasBGill 14:55802ce40285 466 lcd.clear();
ThomasBGill 14:55802ce40285 467 lcd.printString("@ Player", 0 ,0);
ThomasBGill 14:55802ce40285 468 lcd.printString("# Wall", 0, 1);
ThomasBGill 14:55802ce40285 469 lcd.printString(". Floor", 0, 2);
ThomasBGill 14:55802ce40285 470 lcd.printString("= Chest", 0, 3);
ThomasBGill 14:55802ce40285 471 lcd.printString("/ Open Chest", 0, 4);
ThomasBGill 15:05a227f970c2 472
ThomasBGill 14:55802ce40285 473
ThomasBGill 14:55802ce40285 474 while(1) {
ThomasBGill 14:55802ce40285 475 Sleep();
ThomasBGill 14:55802ce40285 476
ThomasBGill 14:55802ce40285 477 if(ActFlag) {
ThomasBGill 14:55802ce40285 478 ActFlag = 0;
ThomasBGill 14:55802ce40285 479 }
ThomasBGill 14:55802ce40285 480 if(DirFlag) {
ThomasBGill 14:55802ce40285 481 DirFlag = 0;
ThomasBGill 14:55802ce40285 482 break;
ThomasBGill 14:55802ce40285 483 }
ThomasBGill 14:55802ce40285 484 if(StartFlag) {
ThomasBGill 14:55802ce40285 485 StartFlag = 0;
ThomasBGill 14:55802ce40285 486 break;
ThomasBGill 14:55802ce40285 487 }
ThomasBGill 14:55802ce40285 488 }
ThomasBGill 8:ee857f0147aa 489 }
ThomasBGill 8:ee857f0147aa 490
ThomasBGill 9:3cad581b5419 491 void StartMenu()
ThomasBGill 9:3cad581b5419 492 {
ThomasBGill 13:2195ec8bc9ff 493 int menu = 0;
ThomasBGill 9:3cad581b5419 494
ThomasBGill 14:55802ce40285 495 char buffer[14];
ThomasBGill 14:55802ce40285 496 int write = sprintf(buffer,"Health %d/15",ph); // print formatted data to buffer
ThomasBGill 14:55802ce40285 497
ThomasBGill 14:55802ce40285 498
ThomasBGill 13:2195ec8bc9ff 499 while(1) {
ThomasBGill 13:2195ec8bc9ff 500 if(menu == 0) {
ThomasBGill 13:2195ec8bc9ff 501 lcd.clear();
ThomasBGill 14:55802ce40285 502 lcd.printString(buffer, 0, 0);
ThomasBGill 14:55802ce40285 503 lcd.printString("Map <", 0, 2);
ThomasBGill 14:55802ce40285 504 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 505 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 506 lcd.printString("Continue", 0, 5);
ThomasBGill 13:2195ec8bc9ff 507 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 508 Sleep();
ThomasBGill 13:2195ec8bc9ff 509 } else if (menu == 1) {
ThomasBGill 13:2195ec8bc9ff 510 lcd.clear();
ThomasBGill 14:55802ce40285 511 lcd.printString(buffer, 0, 0);
ThomasBGill 14:55802ce40285 512 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 513 lcd.printString("Map Legend <", 0, 3);
ThomasBGill 14:55802ce40285 514 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 515 lcd.printString("Continue", 0, 5);
ThomasBGill 13:2195ec8bc9ff 516 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 517 Sleep();
ThomasBGill 13:2195ec8bc9ff 518 } else if (menu == 2) {
ThomasBGill 13:2195ec8bc9ff 519 lcd.clear();
ThomasBGill 14:55802ce40285 520 lcd.printString(buffer, 0, 0);
ThomasBGill 14:55802ce40285 521 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 522 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 523 lcd.printString("Inventory <", 0, 4);
ThomasBGill 14:55802ce40285 524 lcd.printString("Continue", 0, 5);
ThomasBGill 14:55802ce40285 525 lcd.refresh();
ThomasBGill 14:55802ce40285 526 Sleep();
ThomasBGill 15:05a227f970c2 527 } else if (menu == 3) {
ThomasBGill 14:55802ce40285 528 lcd.clear();
ThomasBGill 14:55802ce40285 529 lcd.printString(buffer, 0, 0);
ThomasBGill 14:55802ce40285 530 lcd.printString("Map", 0, 2);
ThomasBGill 14:55802ce40285 531 lcd.printString("Map Legend", 0, 3);
ThomasBGill 14:55802ce40285 532 lcd.printString("Inventory", 0, 4);
ThomasBGill 14:55802ce40285 533 lcd.printString("Continue <", 0, 5);
ThomasBGill 13:2195ec8bc9ff 534 lcd.refresh();
ThomasBGill 13:2195ec8bc9ff 535 Sleep();
ThomasBGill 9:3cad581b5419 536 }
ThomasBGill 13:2195ec8bc9ff 537
ThomasBGill 13:2195ec8bc9ff 538 if(DirFlag) {
ThomasBGill 13:2195ec8bc9ff 539 DirFlag = 0;
ThomasBGill 14:55802ce40285 540 if((Down || Right) && menu < 3) {
ThomasBGill 13:2195ec8bc9ff 541 menu++;
ThomasBGill 13:2195ec8bc9ff 542 } else if((Up ||Left) && menu > 0)
ThomasBGill 13:2195ec8bc9ff 543 menu--;
ThomasBGill 13:2195ec8bc9ff 544 }
ThomasBGill 13:2195ec8bc9ff 545 if(ActFlag) {
ThomasBGill 13:2195ec8bc9ff 546 ActFlag = 0;
ThomasBGill 13:2195ec8bc9ff 547 if(menu == 0) {
ThomasBGill 13:2195ec8bc9ff 548 Map();
ThomasBGill 13:2195ec8bc9ff 549 } else if(menu == 1) {
ThomasBGill 14:55802ce40285 550 MapLegend();
ThomasBGill 14:55802ce40285 551 } else if(menu == 2) {
ThomasBGill 13:2195ec8bc9ff 552 Inventory();
ThomasBGill 13:2195ec8bc9ff 553 } else {
ThomasBGill 13:2195ec8bc9ff 554 break;
ThomasBGill 13:2195ec8bc9ff 555 }
ThomasBGill 13:2195ec8bc9ff 556 }
ThomasBGill 16:a26d7519830e 557 if(StartFlag) {
ThomasBGill 16:a26d7519830e 558 StartFlag = 0;
ThomasBGill 16:a26d7519830e 559 }
ThomasBGill 9:3cad581b5419 560 }
ThomasBGill 10:59c874d006ab 561 }
ThomasBGill 9:3cad581b5419 562
ThomasBGill 13:2195ec8bc9ff 563
ThomasBGill 10:59c874d006ab 564 void Intro()
ThomasBGill 10:59c874d006ab 565 {
ThomasBGill 10:59c874d006ab 566 lcd.clear();
ThomasBGill 10:59c874d006ab 567 lcd.printString("TBG RPG", 20, 2);
ThomasBGill 10:59c874d006ab 568 lcd.refresh();
ThomasBGill 10:59c874d006ab 569 wait(1.0);
ThomasBGill 10:59c874d006ab 570 }
ThomasBGill 10:59c874d006ab 571
ThomasBGill 10:59c874d006ab 572 void LevelScreen()
ThomasBGill 10:59c874d006ab 573 {
ThomasBGill 12:30a242706847 574 char buffer[14];
ThomasBGill 12:30a242706847 575
ThomasBGill 12:30a242706847 576 int write = sprintf(buffer,"Level %d",level); // print formatted data to buffer
ThomasBGill 11:b86a15d26de9 577
ThomasBGill 10:59c874d006ab 578 lcd.clear();
ThomasBGill 10:59c874d006ab 579 lcd.printString(buffer, 20, 2);
ThomasBGill 10:59c874d006ab 580 lcd.refresh();
ThomasBGill 10:59c874d006ab 581 wait(1.0);
ThomasBGill 10:59c874d006ab 582
ThomasBGill 10:59c874d006ab 583 }
ThomasBGill 10:59c874d006ab 584
ThomasBGill 15:05a227f970c2 585 void getItem()
ThomasBGill 12:30a242706847 586 {
ThomasBGill 15:05a227f970c2 587
ThomasBGill 13:2195ec8bc9ff 588 int r = rand()%10;
ThomasBGill 12:30a242706847 589
ThomasBGill 12:30a242706847 590 DirFlag = 0;
ThomasBGill 12:30a242706847 591
ThomasBGill 15:05a227f970c2 592 lcd.clear();
ThomasBGill 15:05a227f970c2 593 lcd.printString("Do you want to", 0, 1);
ThomasBGill 15:05a227f970c2 594 lcd.printString("take the", 0, 2);
ThomasBGill 15:05a227f970c2 595 lcd.printString(ItemList[r].ItemName, 0, 3);
ThomasBGill 15:05a227f970c2 596 lcd.printString("-Yes (Action)", 0, 4);
ThomasBGill 15:05a227f970c2 597 lcd.printString("-No (Other)", 0, 5);
ThomasBGill 15:05a227f970c2 598 lcd.refresh();
ThomasBGill 16:a26d7519830e 599 wait(1.0);
ThomasBGill 15:05a227f970c2 600 Sleep();
ThomasBGill 15:05a227f970c2 601
ThomasBGill 15:05a227f970c2 602
ThomasBGill 15:05a227f970c2 603 if(ActFlag) {
ThomasBGill 15:05a227f970c2 604
ThomasBGill 15:05a227f970c2 605 ActFlag = 0;
ThomasBGill 15:05a227f970c2 606
ThomasBGill 15:05a227f970c2 607 if (r > 5) {
ThomasBGill 15:05a227f970c2 608 pa = r;
ThomasBGill 15:05a227f970c2 609 } else {
ThomasBGill 15:05a227f970c2 610 pw = r;
ThomasBGill 15:05a227f970c2 611 }
ThomasBGill 15:05a227f970c2 612
ThomasBGill 15:05a227f970c2 613 lcd.clear();
ThomasBGill 15:05a227f970c2 614 lcd.printString("You take the", 0, 1);
ThomasBGill 15:05a227f970c2 615 lcd.printString(ItemList[r].ItemName, 0, 2);
ThomasBGill 15:05a227f970c2 616 lcd.refresh();
ThomasBGill 16:a26d7519830e 617 wait(1.0);
ThomasBGill 16:a26d7519830e 618 Sleep();
ThomasBGill 15:05a227f970c2 619
ThomasBGill 16:a26d7519830e 620 } else {
ThomasBGill 16:a26d7519830e 621
ThomasBGill 16:a26d7519830e 622 StartFlag = 0;
ThomasBGill 15:05a227f970c2 623 DirFlag = 0;
ThomasBGill 15:05a227f970c2 624
ThomasBGill 13:2195ec8bc9ff 625 lcd.clear();
ThomasBGill 15:05a227f970c2 626 lcd.printString("You leave the", 0, 1);
ThomasBGill 15:05a227f970c2 627 lcd.printString(ItemList[r].ItemName, 0, 2);
ThomasBGill 15:05a227f970c2 628 lcd.refresh();
ThomasBGill 16:a26d7519830e 629 wait(1.0);
ThomasBGill 16:a26d7519830e 630 Sleep();
ThomasBGill 15:05a227f970c2 631 }
ThomasBGill 15:05a227f970c2 632 }
ThomasBGill 15:05a227f970c2 633
ThomasBGill 15:05a227f970c2 634 void BoobyTrap()
ThomasBGill 15:05a227f970c2 635 {
ThomasBGill 15:05a227f970c2 636
ThomasBGill 15:05a227f970c2 637 int damage = rand()%5;
ThomasBGill 15:05a227f970c2 638
ThomasBGill 15:05a227f970c2 639 if(damage != 0) {
ThomasBGill 15:05a227f970c2 640
ThomasBGill 15:05a227f970c2 641 ph = ph - damage;
ThomasBGill 15:05a227f970c2 642
ThomasBGill 15:05a227f970c2 643 char buffer[15];
ThomasBGill 15:05a227f970c2 644 int write = sprintf(buffer, "You recive %d", damage);
ThomasBGill 15:05a227f970c2 645
ThomasBGill 15:05a227f970c2 646 lcd.clear();
ThomasBGill 15:05a227f970c2 647 lcd.printString("The chest is", 0, 0);
ThomasBGill 16:a26d7519830e 648 lcd.printString("booby trapped!", 0, 1);
ThomasBGill 15:05a227f970c2 649 lcd.printString(buffer, 0, 3);
ThomasBGill 15:05a227f970c2 650 lcd.printString("damage", 0, 4);
ThomasBGill 15:05a227f970c2 651 lcd.refresh();
ThomasBGill 15:05a227f970c2 652 wait(1.0);
ThomasBGill 13:2195ec8bc9ff 653 Sleep();
ThomasBGill 12:30a242706847 654
ThomasBGill 15:05a227f970c2 655 //Check if player is dead
ThomasBGill 15:05a227f970c2 656 if(ph < 0) {
ThomasBGill 15:05a227f970c2 657 GameOver();
ThomasBGill 15:05a227f970c2 658 }
ThomasBGill 15:05a227f970c2 659 } else {
ThomasBGill 12:30a242706847 660
ThomasBGill 15:05a227f970c2 661 lcd.clear();
ThomasBGill 15:05a227f970c2 662 lcd.printString("The chest is", 0, 0);
ThomasBGill 16:a26d7519830e 663 lcd.printString("booby trapped", 0, 1);
ThomasBGill 16:a26d7519830e 664 lcd.printString("but the trap", 0, 2);
ThomasBGill 16:a26d7519830e 665 lcd.printString("fails", 0, 3);
ThomasBGill 15:05a227f970c2 666 lcd.refresh();
ThomasBGill 15:05a227f970c2 667 wait(1.0);
ThomasBGill 15:05a227f970c2 668 Sleep();
ThomasBGill 15:05a227f970c2 669
ThomasBGill 15:05a227f970c2 670 }
ThomasBGill 15:05a227f970c2 671 }
ThomasBGill 13:2195ec8bc9ff 672
ThomasBGill 15:05a227f970c2 673 void RevealMap()
ThomasBGill 15:05a227f970c2 674 {
ThomasBGill 15:05a227f970c2 675
ThomasBGill 15:05a227f970c2 676 for(int i = 0; i < 84; i++) {
ThomasBGill 15:05a227f970c2 677 for(int j = 0; j < 48; j++) {
ThomasBGill 15:05a227f970c2 678
ThomasBGill 15:05a227f970c2 679 if(map[i][j] == FLOOR) {
ThomasBGill 15:05a227f970c2 680 map[i][j] = FLOOR_SEEN;
ThomasBGill 15:05a227f970c2 681 }
ThomasBGill 15:05a227f970c2 682 }
ThomasBGill 15:05a227f970c2 683 }
ThomasBGill 12:30a242706847 684
ThomasBGill 15:05a227f970c2 685 lcd.clear();
ThomasBGill 15:05a227f970c2 686 lcd.printString("You find a map", 0, 0);
ThomasBGill 16:a26d7519830e 687 lcd.printString("of the current", 0, 1);
ThomasBGill 16:a26d7519830e 688 lcd.printString("level inside", 0, 2);
ThomasBGill 16:a26d7519830e 689 lcd.printString("the chest", 0, 3);
ThomasBGill 15:05a227f970c2 690 lcd.refresh();
ThomasBGill 15:05a227f970c2 691 wait(1.0);
ThomasBGill 15:05a227f970c2 692 Sleep();
ThomasBGill 15:05a227f970c2 693 }
ThomasBGill 15:05a227f970c2 694
ThomasBGill 15:05a227f970c2 695 void Potion()
ThomasBGill 15:05a227f970c2 696 {
ThomasBGill 15:05a227f970c2 697
ThomasBGill 15:05a227f970c2 698 int p = rand()%5; //0- Poison, 1- Teleport, Else- Full heal
ThomasBGill 15:05a227f970c2 699
ThomasBGill 15:05a227f970c2 700 lcd.clear();
ThomasBGill 15:05a227f970c2 701 lcd.printString("You find a", 0, 0);
ThomasBGill 16:a26d7519830e 702 lcd.printString("potion inside", 0, 1);
ThomasBGill 16:a26d7519830e 703 lcd.printString("the chest", 0, 2);
ThomasBGill 15:05a227f970c2 704 lcd.printString("Drink (Action)", 0, 4);
ThomasBGill 15:05a227f970c2 705 lcd.printString("Leave (Other)", 0, 5);
ThomasBGill 15:05a227f970c2 706 lcd.refresh();
ThomasBGill 15:05a227f970c2 707 wait(1.0);
ThomasBGill 15:05a227f970c2 708 Sleep();
ThomasBGill 15:05a227f970c2 709
ThomasBGill 15:05a227f970c2 710 if(ActFlag) { //Potion drunk
ThomasBGill 15:05a227f970c2 711 ActFlag = 0;
ThomasBGill 15:05a227f970c2 712
ThomasBGill 15:05a227f970c2 713 if(p == 0) { //Poison
ThomasBGill 15:05a227f970c2 714
ThomasBGill 15:05a227f970c2 715 int damage = rand()%4 + 1;
ThomasBGill 15:05a227f970c2 716
ThomasBGill 15:05a227f970c2 717 ph = ph - damage;
ThomasBGill 15:05a227f970c2 718
ThomasBGill 15:05a227f970c2 719 char buffer[15];
ThomasBGill 15:05a227f970c2 720 int write = sprintf(buffer, "%d damage", damage);
ThomasBGill 13:2195ec8bc9ff 721
ThomasBGill 13:2195ec8bc9ff 722 lcd.clear();
ThomasBGill 15:05a227f970c2 723 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 724 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 725 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 726 lcd.printString("ill.", 0, 3);
ThomasBGill 15:05a227f970c2 727 lcd.printString("You take", 0, 4);
ThomasBGill 15:05a227f970c2 728 lcd.printString(buffer, 0, 5);
ThomasBGill 13:2195ec8bc9ff 729 lcd.refresh();
ThomasBGill 15:05a227f970c2 730 wait(1.0);
ThomasBGill 15:05a227f970c2 731 Sleep();
ThomasBGill 15:05a227f970c2 732
ThomasBGill 15:05a227f970c2 733 //Check if player is dead
ThomasBGill 15:05a227f970c2 734 if(ph < 0) {
ThomasBGill 15:05a227f970c2 735 GameOver();
ThomasBGill 15:05a227f970c2 736 }
ThomasBGill 15:05a227f970c2 737 } else if(p == 1) { //Teleport
ThomasBGill 12:30a242706847 738
ThomasBGill 15:05a227f970c2 739 lcd.clear();
ThomasBGill 15:05a227f970c2 740 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 741 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 742 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 743 lcd.printString("your body", 0, 3);
ThomasBGill 15:05a227f970c2 744 lcd.printString("being", 0, 4);
ThomasBGill 15:05a227f970c2 745 lcd.printString("transported", 0, 5);
ThomasBGill 15:05a227f970c2 746 lcd.refresh();
ThomasBGill 15:05a227f970c2 747 wait(1.0);
ThomasBGill 15:05a227f970c2 748 Sleep();
ThomasBGill 15:05a227f970c2 749
ThomasBGill 15:05a227f970c2 750 GameLoop();
ThomasBGill 15:05a227f970c2 751
ThomasBGill 15:05a227f970c2 752 } else { //Full heal
ThomasBGill 15:05a227f970c2 753
ThomasBGill 15:05a227f970c2 754 ph = 15;
ThomasBGill 13:2195ec8bc9ff 755
ThomasBGill 13:2195ec8bc9ff 756 lcd.clear();
ThomasBGill 15:05a227f970c2 757 lcd.printString("You drink the", 0, 0);
ThomasBGill 15:05a227f970c2 758 lcd.printString("potion and", 0, 1);
ThomasBGill 15:05a227f970c2 759 lcd.printString("suddenly feel", 0, 2);
ThomasBGill 15:05a227f970c2 760 lcd.printString("all your", 0, 3);
ThomasBGill 15:05a227f970c2 761 lcd.printString("wounds heal", 0, 4);
ThomasBGill 13:2195ec8bc9ff 762 lcd.refresh();
ThomasBGill 15:05a227f970c2 763 wait(1.0);
ThomasBGill 15:05a227f970c2 764 Sleep();
ThomasBGill 13:2195ec8bc9ff 765 }
ThomasBGill 15:05a227f970c2 766 } else { //Leave the potion
ThomasBGill 15:05a227f970c2 767 DirFlag = 0;
ThomasBGill 15:05a227f970c2 768 StartFlag = 0;
ThomasBGill 15:05a227f970c2 769 lcd.clear();
ThomasBGill 15:05a227f970c2 770 lcd.printString("You walk away", 0, 0);
ThomasBGill 15:05a227f970c2 771 lcd.printString("and leave the", 0, 1);
ThomasBGill 15:05a227f970c2 772 lcd.printString("potion", 0, 2);
ThomasBGill 15:05a227f970c2 773 lcd.refresh();
ThomasBGill 15:05a227f970c2 774 wait(1.0);
ThomasBGill 15:05a227f970c2 775 Sleep();
ThomasBGill 15:05a227f970c2 776 }
ThomasBGill 15:05a227f970c2 777 }
ThomasBGill 13:2195ec8bc9ff 778
ThomasBGill 15:05a227f970c2 779 void Chest()
ThomasBGill 15:05a227f970c2 780 {
ThomasBGill 15:05a227f970c2 781 int c = rand()%4; //0- Item, 1- Booby trap, 2- Map, Else- Potion
ThomasBGill 13:2195ec8bc9ff 782
ThomasBGill 15:05a227f970c2 783 if(c == 0) {
ThomasBGill 15:05a227f970c2 784 getItem();
ThomasBGill 15:05a227f970c2 785 } else if(c == 1) {
ThomasBGill 15:05a227f970c2 786 BoobyTrap();
ThomasBGill 15:05a227f970c2 787 } else if(c == 2) {
ThomasBGill 15:05a227f970c2 788 RevealMap();
ThomasBGill 15:05a227f970c2 789 } else {
ThomasBGill 15:05a227f970c2 790 Potion();
ThomasBGill 12:30a242706847 791 }
ThomasBGill 15:05a227f970c2 792
ThomasBGill 15:05a227f970c2 793 map[px][py] = CHEST_OPENED;
ThomasBGill 15:05a227f970c2 794
ThomasBGill 12:30a242706847 795 }
ThomasBGill 12:30a242706847 796
ThomasBGill 10:59c874d006ab 797 void GameLoop()
ThomasBGill 10:59c874d006ab 798 {
ThomasBGill 10:59c874d006ab 799 while(1) {
ThomasBGill 10:59c874d006ab 800
ThomasBGill 11:b86a15d26de9 801 level++;
ThomasBGill 11:b86a15d26de9 802
ThomasBGill 11:b86a15d26de9 803 World();
ThomasBGill 11:b86a15d26de9 804
ThomasBGill 11:b86a15d26de9 805 LevelScreen();
ThomasBGill 19:1ab2d83ebffa 806
ThomasBGill 18:98ea2b787894 807 RevealMap();
ThomasBGill 11:b86a15d26de9 808
ThomasBGill 11:b86a15d26de9 809 while(1) {
ThomasBGill 11:b86a15d26de9 810
ThomasBGill 16:a26d7519830e 811 ActFlag = 0;
ThomasBGill 16:a26d7519830e 812 StartFlag = 0;
ThomasBGill 16:a26d7519830e 813 DirFlag = 0;
ThomasBGill 16:a26d7519830e 814
ThomasBGill 11:b86a15d26de9 815 PlayerCamera();
ThomasBGill 12:30a242706847 816
ThomasBGill 12:30a242706847 817 if(map[px][py] == CHEST) {
ThomasBGill 12:30a242706847 818 Chest();
ThomasBGill 12:30a242706847 819 }
ThomasBGill 12:30a242706847 820
ThomasBGill 12:30a242706847 821 if(px == exx && py == exy) {
ThomasBGill 12:30a242706847 822
ThomasBGill 12:30a242706847 823 break;
ThomasBGill 12:30a242706847 824
ThomasBGill 12:30a242706847 825 }
ThomasBGill 12:30a242706847 826
ThomasBGill 11:b86a15d26de9 827 Sleep();
ThomasBGill 10:59c874d006ab 828
ThomasBGill 10:59c874d006ab 829
ThomasBGill 11:b86a15d26de9 830 if(DirFlag) {
ThomasBGill 11:b86a15d26de9 831
ThomasBGill 11:b86a15d26de9 832 DirFlag = 0;
ThomasBGill 10:59c874d006ab 833
ThomasBGill 11:b86a15d26de9 834 PlayerMove();
ThomasBGill 13:2195ec8bc9ff 835
ThomasBGill 19:1ab2d83ebffa 836 if(rand()%60 == 0) {
ThomasBGill 19:1ab2d83ebffa 837 if(ph < 15) {
ThomasBGill 19:1ab2d83ebffa 838 ph++;
ThomasBGill 19:1ab2d83ebffa 839 }
ThomasBGill 19:1ab2d83ebffa 840 }
ThomasBGill 19:1ab2d83ebffa 841
ThomasBGill 18:98ea2b787894 842 if(rand()%50 == 0) {
ThomasBGill 13:2195ec8bc9ff 843 Fight();
ThomasBGill 13:2195ec8bc9ff 844 }
ThomasBGill 13:2195ec8bc9ff 845
ThomasBGill 11:b86a15d26de9 846 }
ThomasBGill 11:b86a15d26de9 847 if(StartFlag) {
ThomasBGill 10:59c874d006ab 848
ThomasBGill 11:b86a15d26de9 849 StartFlag = 0;
ThomasBGill 10:59c874d006ab 850
ThomasBGill 11:b86a15d26de9 851 StartMenu();
ThomasBGill 11:b86a15d26de9 852 }
ThomasBGill 13:2195ec8bc9ff 853 if(ActFlag) {
ThomasBGill 13:2195ec8bc9ff 854
ThomasBGill 13:2195ec8bc9ff 855 ActFlag = 0;
ThomasBGill 13:2195ec8bc9ff 856 }
ThomasBGill 10:59c874d006ab 857 }
ThomasBGill 10:59c874d006ab 858 }
ThomasBGill 10:59c874d006ab 859 }
ThomasBGill 10:59c874d006ab 860
ThomasBGill 10:59c874d006ab 861 void MainMenu()
ThomasBGill 10:59c874d006ab 862 {
ThomasBGill 13:2195ec8bc9ff 863 level = 0;
ThomasBGill 13:2195ec8bc9ff 864
ThomasBGill 13:2195ec8bc9ff 865 //Player Health
ThomasBGill 13:2195ec8bc9ff 866 ph = 15;
ThomasBGill 13:2195ec8bc9ff 867
ThomasBGill 13:2195ec8bc9ff 868 //Player weapon
ThomasBGill 13:2195ec8bc9ff 869 pw = 0; //0 to 4
ThomasBGill 13:2195ec8bc9ff 870
ThomasBGill 13:2195ec8bc9ff 871 //Player armour
ThomasBGill 13:2195ec8bc9ff 872 pa = 5; //5 to 9
ThomasBGill 13:2195ec8bc9ff 873
ThomasBGill 12:30a242706847 874 bool menu = 0;
ThomasBGill 10:59c874d006ab 875
ThomasBGill 10:59c874d006ab 876 while(1) {
ThomasBGill 10:59c874d006ab 877 lcd.clear();
ThomasBGill 10:59c874d006ab 878 if(menu == 0) {
ThomasBGill 10:59c874d006ab 879 lcd.printString("New Game <", 20, 1);
ThomasBGill 10:59c874d006ab 880 lcd.printString("Options",20,3);
ThomasBGill 10:59c874d006ab 881 lcd.refresh();
ThomasBGill 10:59c874d006ab 882 Sleep();
ThomasBGill 10:59c874d006ab 883 } else {
ThomasBGill 10:59c874d006ab 884 lcd.printString("New Game", 20, 1);
ThomasBGill 10:59c874d006ab 885 lcd.printString("Options <",20,3);
ThomasBGill 10:59c874d006ab 886 lcd.refresh();
ThomasBGill 10:59c874d006ab 887 Sleep();
ThomasBGill 10:59c874d006ab 888 }
ThomasBGill 10:59c874d006ab 889
ThomasBGill 10:59c874d006ab 890 if(DirFlag) {
ThomasBGill 10:59c874d006ab 891
ThomasBGill 10:59c874d006ab 892 DirFlag = 0;
ThomasBGill 10:59c874d006ab 893
ThomasBGill 10:59c874d006ab 894 menu = !menu;
ThomasBGill 10:59c874d006ab 895 }
ThomasBGill 13:2195ec8bc9ff 896 if(ActFlag) {
ThomasBGill 10:59c874d006ab 897
ThomasBGill 10:59c874d006ab 898 ActFlag = 0;
ThomasBGill 10:59c874d006ab 899
ThomasBGill 13:2195ec8bc9ff 900 if(menu == 0) {
ThomasBGill 13:2195ec8bc9ff 901 GameLoop();
ThomasBGill 13:2195ec8bc9ff 902 }
ThomasBGill 10:59c874d006ab 903 }
ThomasBGill 10:59c874d006ab 904 }
ThomasBGill 9:3cad581b5419 905 }
ThomasBGill 8:ee857f0147aa 906
ThomasBGill 0:9200b3c387ed 907 int main()
ThomasBGill 0:9200b3c387ed 908 {
ThomasBGill 1:0f774d41584c 909 //Power Saving
ThomasBGill 1:0f774d41584c 910 PHY_PowerDown ();
ThomasBGill 1:0f774d41584c 911 int result = semihost_powerdown();
ThomasBGill 1:0f774d41584c 912
ThomasBGill 10:59c874d006ab 913 Up.rise(&DirPressed);
ThomasBGill 10:59c874d006ab 914 Down.rise(&DirPressed);
ThomasBGill 10:59c874d006ab 915 Right.rise(&DirPressed);
ThomasBGill 10:59c874d006ab 916 Left.rise(&DirPressed);
ThomasBGill 9:3cad581b5419 917 Start.rise(&StartPressed);
ThomasBGill 10:59c874d006ab 918 Act.rise(&ActPressed);
ThomasBGill 9:3cad581b5419 919
ThomasBGill 1:0f774d41584c 920 //Generate random seed
ThomasBGill 0:9200b3c387ed 921 srand(Noise*1000000);
ThomasBGill 1:0f774d41584c 922
ThomasBGill 1:0f774d41584c 923 //Initilize screen
ThomasBGill 0:9200b3c387ed 924 lcd.init();
ThomasBGill 8:ee857f0147aa 925
ThomasBGill 10:59c874d006ab 926 Intro();
ThomasBGill 9:3cad581b5419 927
ThomasBGill 10:59c874d006ab 928 MainMenu();
ThomasBGill 10:59c874d006ab 929 }