Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 PowerControl mbed
main.cpp@19:1ab2d83ebffa, 2015-05-04 (annotated)
- Committer:
- ThomasBGill
- Date:
- Mon May 04 15:25:02 2015 +0000
- Revision:
- 19:1ab2d83ebffa
- Parent:
- 18:98ea2b787894
- Child:
- 20:e54792b89571
New maze algorithm implemented + automatic player healing while walking
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThomasBGill | 0:9200b3c387ed | 1 | #include "mbed.h" |
ThomasBGill | 0:9200b3c387ed | 2 | #include "N5110.h" |
ThomasBGill | 1:0f774d41584c | 3 | #include "PowerControl/PowerControl.h" |
ThomasBGill | 1:0f774d41584c | 4 | #include "PowerControl/EthernetPowerControl.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 | 0:9200b3c387ed | 18 | #define WALL 0 |
ThomasBGill | 0:9200b3c387ed | 19 | #define FLOOR 1 |
ThomasBGill | 0:9200b3c387ed | 20 | #define ENTER 2 |
ThomasBGill | 0:9200b3c387ed | 21 | #define EXIT 3 |
ThomasBGill | 11:b86a15d26de9 | 22 | #define FLOOR_SEEN 4 |
ThomasBGill | 12:30a242706847 | 23 | #define CHEST 5 |
ThomasBGill | 12:30a242706847 | 24 | #define CHEST_OPENED 6 |
ThomasBGill | 0:9200b3c387ed | 25 | |
ThomasBGill | 0:9200b3c387ed | 26 | #define RIGHT 0 |
ThomasBGill | 0:9200b3c387ed | 27 | #define LEFT 1 |
ThomasBGill | 0:9200b3c387ed | 28 | #define UP 2 |
ThomasBGill | 0:9200b3c387ed | 29 | #define DOWN 3 |
ThomasBGill | 0:9200b3c387ed | 30 | |
ThomasBGill | 3:1a25939df22a | 31 | #define SOUTH 0 |
ThomasBGill | 3:1a25939df22a | 32 | #define EAST 1 |
ThomasBGill | 3:1a25939df22a | 33 | |
ThomasBGill | 8:ee857f0147aa | 34 | struct TILES { |
ThomasBGill | 7:cd799c701997 | 35 | char Symbol; // Symbol for this tile |
ThomasBGill | 7:cd799c701997 | 36 | bool Passable; // Can tile be walked on |
ThomasBGill | 7:cd799c701997 | 37 | }; |
ThomasBGill | 7:cd799c701997 | 38 | |
ThomasBGill | 8:ee857f0147aa | 39 | TILES TileList[] = { |
ThomasBGill | 7:cd799c701997 | 40 | { '#', false }, // 0- WALL |
ThomasBGill | 7:cd799c701997 | 41 | { '.', true}, // 1- FLOOR |
ThomasBGill | 7:cd799c701997 | 42 | { '+', true }, // 2- ENTER |
ThomasBGill | 7:cd799c701997 | 43 | { 'x', true }, // 3- EXIT |
ThomasBGill | 11:b86a15d26de9 | 44 | { '.', true}, // 4- FLOOR_SEEN |
ThomasBGill | 12:30a242706847 | 45 | { '=', true}, // 5- CHEST |
ThomasBGill | 12:30a242706847 | 46 | { '/', true}, // 6- CHEST_OPENED |
ThomasBGill | 12:30a242706847 | 47 | }; |
ThomasBGill | 12:30a242706847 | 48 | |
ThomasBGill | 12:30a242706847 | 49 | struct ITEMS { |
ThomasBGill | 13:2195ec8bc9ff | 50 | char ItemName[15]; //Item name |
ThomasBGill | 13:2195ec8bc9ff | 51 | int ItemValue; //Damage/ armour value |
ThomasBGill | 12:30a242706847 | 52 | }; |
ThomasBGill | 12:30a242706847 | 53 | |
ThomasBGill | 12:30a242706847 | 54 | ITEMS ItemList[] = { |
ThomasBGill | 13:2195ec8bc9ff | 55 | //Weapons |
ThomasBGill | 16:a26d7519830e | 56 | { "Dagger", 4}, //0 |
ThomasBGill | 13:2195ec8bc9ff | 57 | { "Axe", 5}, //1 |
ThomasBGill | 13:2195ec8bc9ff | 58 | { "Mace", 6}, //2 |
ThomasBGill | 13:2195ec8bc9ff | 59 | { "Sword", 7}, //3 |
ThomasBGill | 13:2195ec8bc9ff | 60 | { "Warhammer", 10}, //4 |
ThomasBGill | 13:2195ec8bc9ff | 61 | //Armour |
ThomasBGill | 18:98ea2b787894 | 62 | { "Cloth armour", 1}, //5 |
ThomasBGill | 13:2195ec8bc9ff | 63 | { "Leather armour", 2}, //6 |
ThomasBGill | 18:98ea2b787894 | 64 | { "Studded armour", 3}, //7 |
ThomasBGill | 18:98ea2b787894 | 65 | { "Chainmail vest", 4}, //8 |
ThomasBGill | 18:98ea2b787894 | 66 | { "Plate armour", 5}, //9 |
ThomasBGill | 7:cd799c701997 | 67 | }; |
ThomasBGill | 7:cd799c701997 | 68 | |
ThomasBGill | 13:2195ec8bc9ff | 69 | struct ENEMIES { |
ThomasBGill | 17:8790dd599b25 | 70 | char EName[9]; //Enemy name |
ThomasBGill | 13:2195ec8bc9ff | 71 | int EHealth; //Enemy health |
ThomasBGill | 13:2195ec8bc9ff | 72 | int EDamage; //Enemy damage |
ThomasBGill | 13:2195ec8bc9ff | 73 | int EArmour; //Enemy armour |
ThomasBGill | 13:2195ec8bc9ff | 74 | int EDodge; //Enemy dodge chance |
ThomasBGill | 13:2195ec8bc9ff | 75 | int EHit; //Enemy hit chance |
ThomasBGill | 16:a26d7519830e | 76 | int ESpd; //Enemy speed (use for running away during fights) |
ThomasBGill | 13:2195ec8bc9ff | 77 | }; |
ThomasBGill | 13:2195ec8bc9ff | 78 | |
ThomasBGill | 13:2195ec8bc9ff | 79 | ENEMIES EnemyList[] = { |
ThomasBGill | 17:8790dd599b25 | 80 | //Name HP Dmg Arm Dg Ht Spd |
ThomasBGill | 17:8790dd599b25 | 81 | {"Huge Rat", 5, 3, 0, 25, 70, 40}, //0- Huge Rat |
ThomasBGill | 17:8790dd599b25 | 82 | {"Goblin", 6, 3, 2, 25, 60, 30}, //1- Goblin |
ThomasBGill | 17:8790dd599b25 | 83 | {"Skeleton", 8, 5, 3, 10, 50, 10}, //2- Skeleton |
ThomasBGill | 17:8790dd599b25 | 84 | {"Wraith", 5, 4, 0, 40, 60, 50}, //3- Wraith |
ThomasBGill | 17:8790dd599b25 | 85 | {"Ogre", 10, 7, 3, 10, 35, 15}, //4- Ogre |
ThomasBGill | 17:8790dd599b25 | 86 | {"Minotaur", 15, 8, 5, 20, 45, 100}, //5- Minotaur |
ThomasBGill | 13:2195ec8bc9ff | 87 | }; |
ThomasBGill | 7:cd799c701997 | 88 | |
ThomasBGill | 0:9200b3c387ed | 89 | //Variables |
ThomasBGill | 9:3cad581b5419 | 90 | int ActFlag = 0; |
ThomasBGill | 9:3cad581b5419 | 91 | int StartFlag = 0; |
ThomasBGill | 10:59c874d006ab | 92 | int DirFlag = 0; |
ThomasBGill | 0:9200b3c387ed | 93 | |
ThomasBGill | 0:9200b3c387ed | 94 | int map[84][48]; |
ThomasBGill | 0:9200b3c387ed | 95 | |
ThomasBGill | 2:0b0311609edc | 96 | //Enterance coordinates |
ThomasBGill | 2:0b0311609edc | 97 | int enx; |
ThomasBGill | 2:0b0311609edc | 98 | int eny; |
ThomasBGill | 2:0b0311609edc | 99 | |
ThomasBGill | 2:0b0311609edc | 100 | //Exit coordinates |
ThomasBGill | 2:0b0311609edc | 101 | int exx; |
ThomasBGill | 2:0b0311609edc | 102 | int exy; |
ThomasBGill | 2:0b0311609edc | 103 | |
ThomasBGill | 1:0f774d41584c | 104 | int sx; |
ThomasBGill | 1:0f774d41584c | 105 | int sy; |
ThomasBGill | 1:0f774d41584c | 106 | int dir; |
ThomasBGill | 1:0f774d41584c | 107 | |
ThomasBGill | 10:59c874d006ab | 108 | int level; |
ThomasBGill | 10:59c874d006ab | 109 | |
ThomasBGill | 7:cd799c701997 | 110 | //Space type player is on |
ThomasBGill | 7:cd799c701997 | 111 | int pSpace; |
ThomasBGill | 7:cd799c701997 | 112 | |
ThomasBGill | 7:cd799c701997 | 113 | //Player coordinates |
ThomasBGill | 7:cd799c701997 | 114 | int px; |
ThomasBGill | 7:cd799c701997 | 115 | int py; |
ThomasBGill | 2:0b0311609edc | 116 | |
ThomasBGill | 13:2195ec8bc9ff | 117 | //Player Health |
ThomasBGill | 13:2195ec8bc9ff | 118 | int ph = 15; |
ThomasBGill | 13:2195ec8bc9ff | 119 | |
ThomasBGill | 13:2195ec8bc9ff | 120 | //Player weapon |
ThomasBGill | 13:2195ec8bc9ff | 121 | int pw = 0; //0 to 4 |
ThomasBGill | 13:2195ec8bc9ff | 122 | |
ThomasBGill | 13:2195ec8bc9ff | 123 | //Player armour |
ThomasBGill | 13:2195ec8bc9ff | 124 | int pa = 5; //5 to 9 |
ThomasBGill | 13:2195ec8bc9ff | 125 | |
ThomasBGill | 1:0f774d41584c | 126 | //Power Saving |
ThomasBGill | 1:0f774d41584c | 127 | int semihost_powerdown() |
ThomasBGill | 1:0f774d41584c | 128 | { |
ThomasBGill | 1:0f774d41584c | 129 | uint32_t arg; |
ThomasBGill | 1:0f774d41584c | 130 | return __semihost(USR_POWERDOWN, &arg); |
ThomasBGill | 1:0f774d41584c | 131 | } |
ThomasBGill | 1:0f774d41584c | 132 | |
ThomasBGill | 0:9200b3c387ed | 133 | //ISR |
ThomasBGill | 0:9200b3c387ed | 134 | void ActPressed() |
ThomasBGill | 0:9200b3c387ed | 135 | { |
ThomasBGill | 9:3cad581b5419 | 136 | ActFlag = 1; |
ThomasBGill | 0:9200b3c387ed | 137 | } |
ThomasBGill | 0:9200b3c387ed | 138 | void StartPressed() |
ThomasBGill | 0:9200b3c387ed | 139 | { |
ThomasBGill | 9:3cad581b5419 | 140 | StartFlag = 1; |
ThomasBGill | 0:9200b3c387ed | 141 | } |
ThomasBGill | 10:59c874d006ab | 142 | void DirPressed() |
ThomasBGill | 0:9200b3c387ed | 143 | { |
ThomasBGill | 13:2195ec8bc9ff | 144 | DirFlag = 1; |
ThomasBGill | 13:2195ec8bc9ff | 145 | } |
ThomasBGill | 10:59c874d006ab | 146 | |
ThomasBGill | 13:2195ec8bc9ff | 147 | //Voids |
ThomasBGill | 13:2195ec8bc9ff | 148 | void MainMenu(); |
ThomasBGill | 15:05a227f970c2 | 149 | void GameLoop(); |
ThomasBGill | 0:9200b3c387ed | 150 | |
ThomasBGill | 0:9200b3c387ed | 151 | void Walls() |
ThomasBGill | 0:9200b3c387ed | 152 | { |
ThomasBGill | 0:9200b3c387ed | 153 | //Fill map with walls |
ThomasBGill | 0:9200b3c387ed | 154 | for(int i=0; i<84; i++) { |
ThomasBGill | 0:9200b3c387ed | 155 | for (int j=0; j<48; j++) { |
ThomasBGill | 3:1a25939df22a | 156 | |
ThomasBGill | 0:9200b3c387ed | 157 | map[i][j] = WALL; |
ThomasBGill | 0:9200b3c387ed | 158 | } |
ThomasBGill | 0:9200b3c387ed | 159 | } |
ThomasBGill | 0:9200b3c387ed | 160 | } |
ThomasBGill | 0:9200b3c387ed | 161 | |
ThomasBGill | 3:1a25939df22a | 162 | void Floors() |
ThomasBGill | 3:1a25939df22a | 163 | { |
ThomasBGill | 3:1a25939df22a | 164 | //Fill map with floors |
ThomasBGill | 3:1a25939df22a | 165 | for(int i=0; i<84; i++) { |
ThomasBGill | 3:1a25939df22a | 166 | for (int j=0; j<48; j++) { |
ThomasBGill | 3:1a25939df22a | 167 | map[i][j] = FLOOR; |
ThomasBGill | 3:1a25939df22a | 168 | } |
ThomasBGill | 3:1a25939df22a | 169 | } |
ThomasBGill | 3:1a25939df22a | 170 | } |
ThomasBGill | 3:1a25939df22a | 171 | |
ThomasBGill | 9:3cad581b5419 | 172 | void FlashPlayerLocation() |
ThomasBGill | 9:3cad581b5419 | 173 | { |
ThomasBGill | 9:3cad581b5419 | 174 | lcd.setPixel(px,py); |
ThomasBGill | 9:3cad581b5419 | 175 | lcd.refresh(); |
ThomasBGill | 9:3cad581b5419 | 176 | wait(0.5); |
ThomasBGill | 9:3cad581b5419 | 177 | lcd.clearPixel(px,py); |
ThomasBGill | 9:3cad581b5419 | 178 | lcd.refresh(); |
ThomasBGill | 9:3cad581b5419 | 179 | wait(0.5); |
ThomasBGill | 13:2195ec8bc9ff | 180 | } |
ThomasBGill | 9:3cad581b5419 | 181 | |
ThomasBGill | 9:3cad581b5419 | 182 | |
ThomasBGill | 1:0f774d41584c | 183 | void DrawMap() |
ThomasBGill | 1:0f774d41584c | 184 | { |
ThomasBGill | 1:0f774d41584c | 185 | //Draw map on screen |
ThomasBGill | 1:0f774d41584c | 186 | for(int i=0; i<84; i++) { |
ThomasBGill | 1:0f774d41584c | 187 | for (int j=0; j<48; j++) { |
ThomasBGill | 12:30a242706847 | 188 | if(map[i][j] == FLOOR_SEEN || map[i][j] == CHEST_OPENED) { |
ThomasBGill | 1:0f774d41584c | 189 | lcd.clearPixel(i, j); |
ThomasBGill | 1:0f774d41584c | 190 | } else { |
ThomasBGill | 1:0f774d41584c | 191 | lcd.setPixel(i, j); |
ThomasBGill | 1:0f774d41584c | 192 | } |
ThomasBGill | 1:0f774d41584c | 193 | } |
ThomasBGill | 1:0f774d41584c | 194 | } |
ThomasBGill | 1:0f774d41584c | 195 | lcd.refresh(); |
ThomasBGill | 1:0f774d41584c | 196 | } |
ThomasBGill | 1:0f774d41584c | 197 | |
ThomasBGill | 0:9200b3c387ed | 198 | void FirstRoom() |
ThomasBGill | 0:9200b3c387ed | 199 | { |
ThomasBGill | 0:9200b3c387ed | 200 | //Create initial room |
ThomasBGill | 1:0f774d41584c | 201 | int si = rand()%25 + 1; |
ThomasBGill | 1:0f774d41584c | 202 | int sj = rand()%15 + 1; |
ThomasBGill | 0:9200b3c387ed | 203 | |
ThomasBGill | 0:9200b3c387ed | 204 | int sw = rand()%5+5; |
ThomasBGill | 0:9200b3c387ed | 205 | int sh = rand()%5+5; |
ThomasBGill | 0:9200b3c387ed | 206 | |
ThomasBGill | 0:9200b3c387ed | 207 | for(int i = si, w = si + sw; i <w; i++) { |
ThomasBGill | 0:9200b3c387ed | 208 | for (int j = sj, h = sj + sh; j <h; j++) { |
ThomasBGill | 0:9200b3c387ed | 209 | map[i][j] = FLOOR; |
ThomasBGill | 0:9200b3c387ed | 210 | } |
ThomasBGill | 0:9200b3c387ed | 211 | } |
ThomasBGill | 0:9200b3c387ed | 212 | //Create enterance in room |
ThomasBGill | 2:0b0311609edc | 213 | enx = rand()%sw + si; |
ThomasBGill | 2:0b0311609edc | 214 | eny = rand()%sh + sj; |
ThomasBGill | 2:0b0311609edc | 215 | map[enx][eny] = ENTER; |
ThomasBGill | 2:0b0311609edc | 216 | } |
ThomasBGill | 2:0b0311609edc | 217 | |
ThomasBGill | 5:9bd276652111 | 218 | void ExitRoom() |
ThomasBGill | 5:9bd276652111 | 219 | { |
ThomasBGill | 6:ca5db4353c95 | 220 | //Create exit room |
ThomasBGill | 5:9bd276652111 | 221 | int si = rand()%50 + 30; |
ThomasBGill | 5:9bd276652111 | 222 | int sj = rand()%25 + 20; |
ThomasBGill | 5:9bd276652111 | 223 | |
ThomasBGill | 5:9bd276652111 | 224 | int sw = rand()%5+5; |
ThomasBGill | 5:9bd276652111 | 225 | int sh = rand()%5+5; |
ThomasBGill | 5:9bd276652111 | 226 | |
ThomasBGill | 5:9bd276652111 | 227 | for(int i = si, w = si + sw; i <w; i++) { |
ThomasBGill | 5:9bd276652111 | 228 | for (int j = sj, h = sj + sh; j <h; j++) { |
ThomasBGill | 5:9bd276652111 | 229 | map[i][j] = FLOOR; |
ThomasBGill | 5:9bd276652111 | 230 | } |
ThomasBGill | 5:9bd276652111 | 231 | } |
ThomasBGill | 6:ca5db4353c95 | 232 | //Create exit in room |
ThomasBGill | 8:ee857f0147aa | 233 | exx = rand()%sw + si; |
ThomasBGill | 8:ee857f0147aa | 234 | exy = rand()%sh + sj; |
ThomasBGill | 8:ee857f0147aa | 235 | map[exx][exy] = EXIT; |
ThomasBGill | 13:2195ec8bc9ff | 236 | |
ThomasBGill | 5:9bd276652111 | 237 | } |
ThomasBGill | 5:9bd276652111 | 238 | |
ThomasBGill | 2:0b0311609edc | 239 | void DungeonRoomBuilder() |
ThomasBGill | 2:0b0311609edc | 240 | { |
ThomasBGill | 2:0b0311609edc | 241 | sx = rand()%84; |
ThomasBGill | 2:0b0311609edc | 242 | sy = rand()%48; |
ThomasBGill | 2:0b0311609edc | 243 | |
ThomasBGill | 2:0b0311609edc | 244 | //Get length |
ThomasBGill | 2:0b0311609edc | 245 | int sw = rand()%5 + 5; |
ThomasBGill | 2:0b0311609edc | 246 | int sh = rand()%5 + 5; |
ThomasBGill | 2:0b0311609edc | 247 | |
ThomasBGill | 19:1ab2d83ebffa | 248 | /* |
ThomasBGill | 19:1ab2d83ebffa | 249 | int b = 0; |
ThomasBGill | 2:0b0311609edc | 250 | |
ThomasBGill | 19:1ab2d83ebffa | 251 | //Check each space. +1 to variable if wall. If total = w*h then build room |
ThomasBGill | 19:1ab2d83ebffa | 252 | for(int i = sx; i < sx + sw; i++) { |
ThomasBGill | 19:1ab2d83ebffa | 253 | for(int j = sy; j < sy + sh; j++) { |
ThomasBGill | 19:1ab2d83ebffa | 254 | if(map[i][j] == WALL) { |
ThomasBGill | 19:1ab2d83ebffa | 255 | b++; |
ThomasBGill | 19:1ab2d83ebffa | 256 | } |
ThomasBGill | 2:0b0311609edc | 257 | } |
ThomasBGill | 2:0b0311609edc | 258 | } |
ThomasBGill | 19:1ab2d83ebffa | 259 | if(b == sw*sh) { |
ThomasBGill | 19:1ab2d83ebffa | 260 | */ |
ThomasBGill | 19:1ab2d83ebffa | 261 | if(sx + sw < 83 && sy + sh < 47) { |
ThomasBGill | 2:0b0311609edc | 262 | for(int i = sx; i < sx + sw; i++) { |
ThomasBGill | 2:0b0311609edc | 263 | for(int j = sy; j < sy + sh; j++) { |
ThomasBGill | 2:0b0311609edc | 264 | if(i < 84 && j < 48) { |
ThomasBGill | 1:0f774d41584c | 265 | map[i][j] = FLOOR; |
ThomasBGill | 1:0f774d41584c | 266 | } |
ThomasBGill | 1:0f774d41584c | 267 | } |
ThomasBGill | 1:0f774d41584c | 268 | } |
ThomasBGill | 1:0f774d41584c | 269 | } |
ThomasBGill | 19:1ab2d83ebffa | 270 | |
ThomasBGill | 17:8790dd599b25 | 271 | if(rand()%3 == 0) { |
ThomasBGill | 12:30a242706847 | 272 | int i = rand()%sw + sx; |
ThomasBGill | 12:30a242706847 | 273 | int j = rand()%sh + sy; |
ThomasBGill | 12:30a242706847 | 274 | map[i][j] = CHEST; |
ThomasBGill | 12:30a242706847 | 275 | } |
ThomasBGill | 1:0f774d41584c | 276 | } |
ThomasBGill | 1:0f774d41584c | 277 | |
ThomasBGill | 13:2195ec8bc9ff | 278 | int Neighbours(int i, int j) |
ThomasBGill | 4:6482ceb08dc8 | 279 | { |
ThomasBGill | 4:6482ceb08dc8 | 280 | //Check neighbours |
ThomasBGill | 13:2195ec8bc9ff | 281 | int n = 0; |
ThomasBGill | 4:6482ceb08dc8 | 282 | |
ThomasBGill | 13:2195ec8bc9ff | 283 | if(map[i+1][j] == FLOOR) { |
ThomasBGill | 4:6482ceb08dc8 | 284 | n++; |
ThomasBGill | 4:6482ceb08dc8 | 285 | } |
ThomasBGill | 13:2195ec8bc9ff | 286 | if(map[i-1][j] == FLOOR) { |
ThomasBGill | 13:2195ec8bc9ff | 287 | n++; |
ThomasBGill | 13:2195ec8bc9ff | 288 | } |
ThomasBGill | 13:2195ec8bc9ff | 289 | if(map[i][j+1] == FLOOR) { |
ThomasBGill | 4:6482ceb08dc8 | 290 | n++; |
ThomasBGill | 4:6482ceb08dc8 | 291 | } |
ThomasBGill | 13:2195ec8bc9ff | 292 | if(map[i][j-1] == FLOOR) { |
ThomasBGill | 4:6482ceb08dc8 | 293 | n++; |
ThomasBGill | 4:6482ceb08dc8 | 294 | } |
ThomasBGill | 13:2195ec8bc9ff | 295 | |
ThomasBGill | 13:2195ec8bc9ff | 296 | return n; |
ThomasBGill | 4:6482ceb08dc8 | 297 | } |
ThomasBGill | 4:6482ceb08dc8 | 298 | |
ThomasBGill | 10:59c874d006ab | 299 | void DeadEnds(int d) |
ThomasBGill | 4:6482ceb08dc8 | 300 | { |
ThomasBGill | 10:59c874d006ab | 301 | for (int del = d; del > 0; del--) { |
ThomasBGill | 4:6482ceb08dc8 | 302 | for(int i = 0; i < 84; i++) { |
ThomasBGill | 4:6482ceb08dc8 | 303 | for(int j = 0; j < 48; j++) { |
ThomasBGill | 4:6482ceb08dc8 | 304 | |
ThomasBGill | 13:2195ec8bc9ff | 305 | if(Neighbours(i , j) < 2) { |
ThomasBGill | 4:6482ceb08dc8 | 306 | map[i][j] = WALL; |
ThomasBGill | 4:6482ceb08dc8 | 307 | } |
ThomasBGill | 4:6482ceb08dc8 | 308 | } |
ThomasBGill | 4:6482ceb08dc8 | 309 | } |
ThomasBGill | 4:6482ceb08dc8 | 310 | } |
ThomasBGill | 4:6482ceb08dc8 | 311 | } |
ThomasBGill | 4:6482ceb08dc8 | 312 | |
ThomasBGill | 5:9bd276652111 | 313 | void Border() |
ThomasBGill | 5:9bd276652111 | 314 | { |
ThomasBGill | 5:9bd276652111 | 315 | |
ThomasBGill | 5:9bd276652111 | 316 | for(int i = 0; i < 84; i++) { |
ThomasBGill | 5:9bd276652111 | 317 | for(int j = 0; j < 48; j++) { |
ThomasBGill | 5:9bd276652111 | 318 | |
ThomasBGill | 5:9bd276652111 | 319 | if(i == 0 || i == 83 || j == 0 || j == 47) { |
ThomasBGill | 5:9bd276652111 | 320 | |
ThomasBGill | 5:9bd276652111 | 321 | map[i][j] = WALL; |
ThomasBGill | 5:9bd276652111 | 322 | |
ThomasBGill | 5:9bd276652111 | 323 | } |
ThomasBGill | 5:9bd276652111 | 324 | } |
ThomasBGill | 5:9bd276652111 | 325 | } |
ThomasBGill | 5:9bd276652111 | 326 | } |
ThomasBGill | 4:6482ceb08dc8 | 327 | |
ThomasBGill | 9:3cad581b5419 | 328 | void RandFloor(int r) |
ThomasBGill | 9:3cad581b5419 | 329 | { |
ThomasBGill | 9:3cad581b5419 | 330 | |
ThomasBGill | 9:3cad581b5419 | 331 | for(int space = rand()%50 + r; space > 0; space--) { |
ThomasBGill | 9:3cad581b5419 | 332 | |
ThomasBGill | 9:3cad581b5419 | 333 | int i = rand()% 84; |
ThomasBGill | 9:3cad581b5419 | 334 | int j = rand()% 48; |
ThomasBGill | 9:3cad581b5419 | 335 | |
ThomasBGill | 9:3cad581b5419 | 336 | if(rand()%2 == 0 && map[i][j] == WALL) { |
ThomasBGill | 9:3cad581b5419 | 337 | map[i][j] = FLOOR; |
ThomasBGill | 9:3cad581b5419 | 338 | } |
ThomasBGill | 9:3cad581b5419 | 339 | } |
ThomasBGill | 9:3cad581b5419 | 340 | |
ThomasBGill | 9:3cad581b5419 | 341 | } |
ThomasBGill | 9:3cad581b5419 | 342 | |
ThomasBGill | 19:1ab2d83ebffa | 343 | void MazeOld() |
ThomasBGill | 2:0b0311609edc | 344 | { |
ThomasBGill | 18:98ea2b787894 | 345 | for(int i = 1; i < 83; i+=2) { |
ThomasBGill | 18:98ea2b787894 | 346 | for(int j = 1; j < 47; j+=2) { |
ThomasBGill | 2:0b0311609edc | 347 | |
ThomasBGill | 5:9bd276652111 | 348 | if(map[i][j] == WALL) { |
ThomasBGill | 5:9bd276652111 | 349 | map[i][j] = FLOOR; |
ThomasBGill | 5:9bd276652111 | 350 | } |
ThomasBGill | 2:0b0311609edc | 351 | |
ThomasBGill | 3:1a25939df22a | 352 | dir = rand()%2; //South or east |
ThomasBGill | 2:0b0311609edc | 353 | |
ThomasBGill | 4:6482ceb08dc8 | 354 | |
ThomasBGill | 5:9bd276652111 | 355 | if(dir == SOUTH && j < 47 && map[i][j+1] == WALL) { |
ThomasBGill | 3:1a25939df22a | 356 | map[i][j+1] = FLOOR; |
ThomasBGill | 2:0b0311609edc | 357 | } |
ThomasBGill | 5:9bd276652111 | 358 | if(dir == EAST && i < 84 && map[i+1][j] == WALL) { |
ThomasBGill | 3:1a25939df22a | 359 | map[i+1][j] = FLOOR; |
ThomasBGill | 2:0b0311609edc | 360 | } |
ThomasBGill | 2:0b0311609edc | 361 | } |
ThomasBGill | 2:0b0311609edc | 362 | } |
ThomasBGill | 2:0b0311609edc | 363 | } |
ThomasBGill | 2:0b0311609edc | 364 | |
ThomasBGill | 19:1ab2d83ebffa | 365 | void MazeKill() |
ThomasBGill | 19:1ab2d83ebffa | 366 | { |
ThomasBGill | 19:1ab2d83ebffa | 367 | |
ThomasBGill | 19:1ab2d83ebffa | 368 | int move[4] = { UP, DOWN, LEFT, RIGHT}; |
ThomasBGill | 19:1ab2d83ebffa | 369 | |
ThomasBGill | 19:1ab2d83ebffa | 370 | bool moved = true; |
ThomasBGill | 19:1ab2d83ebffa | 371 | |
ThomasBGill | 19:1ab2d83ebffa | 372 | while(moved == true) { |
ThomasBGill | 19:1ab2d83ebffa | 373 | |
ThomasBGill | 19:1ab2d83ebffa | 374 | moved = false; |
ThomasBGill | 19:1ab2d83ebffa | 375 | |
ThomasBGill | 19:1ab2d83ebffa | 376 | for (int s = 0; s < 3; s++) { //Shuffle array |
ThomasBGill | 19:1ab2d83ebffa | 377 | |
ThomasBGill | 19:1ab2d83ebffa | 378 | int r = rand() % 4; |
ThomasBGill | 19:1ab2d83ebffa | 379 | |
ThomasBGill | 19:1ab2d83ebffa | 380 | int temp = move[s]; |
ThomasBGill | 19:1ab2d83ebffa | 381 | |
ThomasBGill | 19:1ab2d83ebffa | 382 | move[s] = move[r]; |
ThomasBGill | 19:1ab2d83ebffa | 383 | |
ThomasBGill | 19:1ab2d83ebffa | 384 | move[r] = temp; |
ThomasBGill | 19:1ab2d83ebffa | 385 | } |
ThomasBGill | 19:1ab2d83ebffa | 386 | |
ThomasBGill | 19:1ab2d83ebffa | 387 | |
ThomasBGill | 19:1ab2d83ebffa | 388 | |
ThomasBGill | 19:1ab2d83ebffa | 389 | for (int i = 0; i < 3; i++) { |
ThomasBGill | 19:1ab2d83ebffa | 390 | if (move[i] == UP) { |
ThomasBGill | 19:1ab2d83ebffa | 391 | if (map[sx][sy - 1] == WALL && Neighbours(sx, sy - 1) == 1 && map[sx][sy - 2] == WALL && Neighbours(sx, sy - 2) == 0 && sy > 3) { |
ThomasBGill | 19:1ab2d83ebffa | 392 | map[sx][sy - 1] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 393 | map[sx][sy - 2] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 394 | sy = sy - 2; |
ThomasBGill | 19:1ab2d83ebffa | 395 | moved = true; |
ThomasBGill | 19:1ab2d83ebffa | 396 | break; |
ThomasBGill | 19:1ab2d83ebffa | 397 | } |
ThomasBGill | 19:1ab2d83ebffa | 398 | } else if (move[i] == DOWN) { |
ThomasBGill | 19:1ab2d83ebffa | 399 | if (map[sx][sy + 1] == WALL && Neighbours(sx, sy + 1) == 1 && map[sx][sy + 2] == WALL && Neighbours(sx, sy + 2) == 0 && sy < 45) { |
ThomasBGill | 19:1ab2d83ebffa | 400 | map[sx][sy + 1] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 401 | map[sx][sy + 2] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 402 | sy = sy + 2; |
ThomasBGill | 19:1ab2d83ebffa | 403 | moved = true; |
ThomasBGill | 19:1ab2d83ebffa | 404 | break; |
ThomasBGill | 19:1ab2d83ebffa | 405 | } |
ThomasBGill | 19:1ab2d83ebffa | 406 | } else if (move[i] == LEFT) { |
ThomasBGill | 19:1ab2d83ebffa | 407 | if (map[sx - 1][sy] == WALL && Neighbours(sx - 1, sy) == 1 && map[sx - 2][sy] == WALL && Neighbours(sx - 2, sy) == 0 && sx > 3) { |
ThomasBGill | 19:1ab2d83ebffa | 408 | map[sx - 1][sy] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 409 | map[sx - 2][sy] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 410 | sx = sx - 2; |
ThomasBGill | 19:1ab2d83ebffa | 411 | moved = true; |
ThomasBGill | 19:1ab2d83ebffa | 412 | break; |
ThomasBGill | 19:1ab2d83ebffa | 413 | } |
ThomasBGill | 19:1ab2d83ebffa | 414 | } else if (move[i] == RIGHT) { |
ThomasBGill | 19:1ab2d83ebffa | 415 | if (map[sx + 1][sy] == WALL && Neighbours(sx + 1, sy) == 1 && map[sx + 2][sy] == WALL && Neighbours(sx + 2, sy) == 0 && sx < 81) { |
ThomasBGill | 19:1ab2d83ebffa | 416 | map[sx + 1][sy] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 417 | map[sx + 2][sy] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 418 | sx = sx + 2; |
ThomasBGill | 19:1ab2d83ebffa | 419 | moved = true; |
ThomasBGill | 19:1ab2d83ebffa | 420 | break; |
ThomasBGill | 19:1ab2d83ebffa | 421 | } |
ThomasBGill | 19:1ab2d83ebffa | 422 | } |
ThomasBGill | 19:1ab2d83ebffa | 423 | } |
ThomasBGill | 19:1ab2d83ebffa | 424 | } |
ThomasBGill | 19:1ab2d83ebffa | 425 | |
ThomasBGill | 19:1ab2d83ebffa | 426 | } |
ThomasBGill | 19:1ab2d83ebffa | 427 | |
ThomasBGill | 19:1ab2d83ebffa | 428 | void Maze() |
ThomasBGill | 18:98ea2b787894 | 429 | { |
ThomasBGill | 18:98ea2b787894 | 430 | sx = 1; |
ThomasBGill | 18:98ea2b787894 | 431 | sy = 1; |
ThomasBGill | 19:1ab2d83ebffa | 432 | |
ThomasBGill | 18:98ea2b787894 | 433 | //Choose random direction |
ThomasBGill | 18:98ea2b787894 | 434 | //Check if 2 cells in direction have no neighbours (excluding current position) |
ThomasBGill | 18:98ea2b787894 | 435 | //If true then build and set new current position |
ThomasBGill | 18:98ea2b787894 | 436 | //If false chose next direction |
ThomasBGill | 19:1ab2d83ebffa | 437 | |
ThomasBGill | 18:98ea2b787894 | 438 | //If cannot move in any direction scan through each cell until there is one which can be built on |
ThomasBGill | 18:98ea2b787894 | 439 | //If scan completes END |
ThomasBGill | 19:1ab2d83ebffa | 440 | |
ThomasBGill | 19:1ab2d83ebffa | 441 | int end = false; |
ThomasBGill | 19:1ab2d83ebffa | 442 | |
ThomasBGill | 19:1ab2d83ebffa | 443 | while(end == false) { |
ThomasBGill | 19:1ab2d83ebffa | 444 | |
ThomasBGill | 19:1ab2d83ebffa | 445 | end = true; |
ThomasBGill | 19:1ab2d83ebffa | 446 | |
ThomasBGill | 19:1ab2d83ebffa | 447 | map[sx][sy] = FLOOR; |
ThomasBGill | 19:1ab2d83ebffa | 448 | |
ThomasBGill | 19:1ab2d83ebffa | 449 | MazeKill(); |
ThomasBGill | 19:1ab2d83ebffa | 450 | |
ThomasBGill | 19:1ab2d83ebffa | 451 | //DrawMap(); |
ThomasBGill | 19:1ab2d83ebffa | 452 | |
ThomasBGill | 19:1ab2d83ebffa | 453 | for(int i = 1; i < 83; i++) { |
ThomasBGill | 19:1ab2d83ebffa | 454 | for(int j = 1; j < 47; j++) { |
ThomasBGill | 19:1ab2d83ebffa | 455 | |
ThomasBGill | 19:1ab2d83ebffa | 456 | if(map[i][j] == WALL && Neighbours(i, j) == 1) { |
ThomasBGill | 19:1ab2d83ebffa | 457 | sx = i; |
ThomasBGill | 19:1ab2d83ebffa | 458 | sy = j; |
ThomasBGill | 19:1ab2d83ebffa | 459 | |
ThomasBGill | 19:1ab2d83ebffa | 460 | end = false; |
ThomasBGill | 19:1ab2d83ebffa | 461 | } |
ThomasBGill | 19:1ab2d83ebffa | 462 | |
ThomasBGill | 19:1ab2d83ebffa | 463 | } |
ThomasBGill | 18:98ea2b787894 | 464 | } |
ThomasBGill | 19:1ab2d83ebffa | 465 | |
ThomasBGill | 19:1ab2d83ebffa | 466 | } |
ThomasBGill | 18:98ea2b787894 | 467 | } |
ThomasBGill | 18:98ea2b787894 | 468 | |
ThomasBGill | 2:0b0311609edc | 469 | void DungeonBuilder() |
ThomasBGill | 0:9200b3c387ed | 470 | { |
ThomasBGill | 1:0f774d41584c | 471 | |
ThomasBGill | 19:1ab2d83ebffa | 472 | Maze(); |
ThomasBGill | 19:1ab2d83ebffa | 473 | |
ThomasBGill | 4:6482ceb08dc8 | 474 | FirstRoom(); |
ThomasBGill | 5:9bd276652111 | 475 | ExitRoom(); |
ThomasBGill | 4:6482ceb08dc8 | 476 | |
ThomasBGill | 18:98ea2b787894 | 477 | int rn = rand()%10 + 6; |
ThomasBGill | 2:0b0311609edc | 478 | |
ThomasBGill | 2:0b0311609edc | 479 | for(int i = rn; i>0; i--) { |
ThomasBGill | 2:0b0311609edc | 480 | DungeonRoomBuilder(); |
ThomasBGill | 2:0b0311609edc | 481 | } |
ThomasBGill | 2:0b0311609edc | 482 | |
ThomasBGill | 19:1ab2d83ebffa | 483 | |
ThomasBGill | 5:9bd276652111 | 484 | |
ThomasBGill | 9:3cad581b5419 | 485 | RandFloor(51); |
ThomasBGill | 9:3cad581b5419 | 486 | |
ThomasBGill | 9:3cad581b5419 | 487 | Border(); |
ThomasBGill | 9:3cad581b5419 | 488 | |
ThomasBGill | 10:59c874d006ab | 489 | DeadEnds(20); |
ThomasBGill | 9:3cad581b5419 | 490 | |
ThomasBGill | 9:3cad581b5419 | 491 | } |
ThomasBGill | 9:3cad581b5419 | 492 | |
ThomasBGill | 9:3cad581b5419 | 493 | void LabyrinthBuilder() |
ThomasBGill | 9:3cad581b5419 | 494 | { |
ThomasBGill | 9:3cad581b5419 | 495 | |
ThomasBGill | 19:1ab2d83ebffa | 496 | Maze(); |
ThomasBGill | 19:1ab2d83ebffa | 497 | |
ThomasBGill | 9:3cad581b5419 | 498 | FirstRoom(); |
ThomasBGill | 9:3cad581b5419 | 499 | ExitRoom(); |
ThomasBGill | 4:6482ceb08dc8 | 500 | |
ThomasBGill | 19:1ab2d83ebffa | 501 | |
ThomasBGill | 3:1a25939df22a | 502 | |
ThomasBGill | 9:3cad581b5419 | 503 | RandFloor(551); |
ThomasBGill | 9:3cad581b5419 | 504 | |
ThomasBGill | 9:3cad581b5419 | 505 | Border(); |
ThomasBGill | 9:3cad581b5419 | 506 | |
ThomasBGill | 2:0b0311609edc | 507 | } |
ThomasBGill | 2:0b0311609edc | 508 | |
ThomasBGill | 2:0b0311609edc | 509 | void World() |
ThomasBGill | 2:0b0311609edc | 510 | { |
ThomasBGill | 2:0b0311609edc | 511 | Walls(); |
ThomasBGill | 12:30a242706847 | 512 | if(level == 5) { |
ThomasBGill | 12:30a242706847 | 513 | LabyrinthBuilder(); |
ThomasBGill | 12:30a242706847 | 514 | } else { |
ThomasBGill | 12:30a242706847 | 515 | DungeonBuilder(); |
ThomasBGill | 12:30a242706847 | 516 | } |
ThomasBGill | 6:ca5db4353c95 | 517 | |
ThomasBGill | 8:ee857f0147aa | 518 | px = enx; |
ThomasBGill | 8:ee857f0147aa | 519 | py = eny; |
ThomasBGill | 8:ee857f0147aa | 520 | |
ThomasBGill | 8:ee857f0147aa | 521 | wait(1.0); |
ThomasBGill | 0:9200b3c387ed | 522 | } |
ThomasBGill | 0:9200b3c387ed | 523 | |
ThomasBGill | 8:ee857f0147aa | 524 | void PlayerCamera() |
ThomasBGill | 8:ee857f0147aa | 525 | { |
ThomasBGill | 8:ee857f0147aa | 526 | lcd.clear(); |
ThomasBGill | 8:ee857f0147aa | 527 | |
ThomasBGill | 8:ee857f0147aa | 528 | int tile; |
ThomasBGill | 8:ee857f0147aa | 529 | |
ThomasBGill | 8:ee857f0147aa | 530 | for(int i = 0; i < 14; i++) { |
ThomasBGill | 8:ee857f0147aa | 531 | for(int j = 0; j < 6; j++) { |
ThomasBGill | 8:ee857f0147aa | 532 | |
ThomasBGill | 8:ee857f0147aa | 533 | if(i == 6 && j == 2) { |
ThomasBGill | 8:ee857f0147aa | 534 | lcd.printString("@", (6*i)+1, j); |
ThomasBGill | 8:ee857f0147aa | 535 | } else { |
ThomasBGill | 8:ee857f0147aa | 536 | int diffx = i - 6; |
ThomasBGill | 8:ee857f0147aa | 537 | int diffy = j - 2; |
ThomasBGill | 8:ee857f0147aa | 538 | |
ThomasBGill | 9:3cad581b5419 | 539 | if(px+diffx < 84 && px+diffx > 0 && py+diffy < 48 && py+diffy > 0) { |
ThomasBGill | 9:3cad581b5419 | 540 | tile = map[px+diffx][py+diffy]; |
ThomasBGill | 9:3cad581b5419 | 541 | } else { |
ThomasBGill | 9:3cad581b5419 | 542 | tile = WALL; |
ThomasBGill | 9:3cad581b5419 | 543 | } |
ThomasBGill | 8:ee857f0147aa | 544 | lcd.printChar(TileList[tile].Symbol, (6*i)+1, j); |
ThomasBGill | 11:b86a15d26de9 | 545 | |
ThomasBGill | 11:b86a15d26de9 | 546 | if(map[px+diffx][py+diffy] == FLOOR) { |
ThomasBGill | 11:b86a15d26de9 | 547 | map[px+diffx][py+diffy] = FLOOR_SEEN; |
ThomasBGill | 11:b86a15d26de9 | 548 | } |
ThomasBGill | 11:b86a15d26de9 | 549 | |
ThomasBGill | 8:ee857f0147aa | 550 | } |
ThomasBGill | 8:ee857f0147aa | 551 | } |
ThomasBGill | 8:ee857f0147aa | 552 | } |
ThomasBGill | 8:ee857f0147aa | 553 | lcd.refresh(); |
ThomasBGill | 8:ee857f0147aa | 554 | } |
ThomasBGill | 8:ee857f0147aa | 555 | |
ThomasBGill | 8:ee857f0147aa | 556 | void PlayerMove() |
ThomasBGill | 8:ee857f0147aa | 557 | { |
ThomasBGill | 8:ee857f0147aa | 558 | if(Up) { |
ThomasBGill | 8:ee857f0147aa | 559 | int tile = map[px][py-1]; |
ThomasBGill | 8:ee857f0147aa | 560 | if(TileList[tile].Passable) { |
ThomasBGill | 8:ee857f0147aa | 561 | py--; |
ThomasBGill | 8:ee857f0147aa | 562 | } |
ThomasBGill | 8:ee857f0147aa | 563 | } |
ThomasBGill | 8:ee857f0147aa | 564 | if(Down) { |
ThomasBGill | 8:ee857f0147aa | 565 | int tile = map[px][py+1]; |
ThomasBGill | 8:ee857f0147aa | 566 | if(TileList[tile].Passable) { |
ThomasBGill | 8:ee857f0147aa | 567 | py++; |
ThomasBGill | 8:ee857f0147aa | 568 | } |
ThomasBGill | 8:ee857f0147aa | 569 | } |
ThomasBGill | 8:ee857f0147aa | 570 | if(Right) { |
ThomasBGill | 8:ee857f0147aa | 571 | int tile = map[px+1][py]; |
ThomasBGill | 8:ee857f0147aa | 572 | if(TileList[tile].Passable) { |
ThomasBGill | 8:ee857f0147aa | 573 | px++; |
ThomasBGill | 8:ee857f0147aa | 574 | } |
ThomasBGill | 8:ee857f0147aa | 575 | } |
ThomasBGill | 8:ee857f0147aa | 576 | if(Left) { |
ThomasBGill | 8:ee857f0147aa | 577 | int tile = map[px-1][py]; |
ThomasBGill | 8:ee857f0147aa | 578 | if(TileList[tile].Passable) { |
ThomasBGill | 8:ee857f0147aa | 579 | px--; |
ThomasBGill | 8:ee857f0147aa | 580 | } |
ThomasBGill | 8:ee857f0147aa | 581 | } |
ThomasBGill | 13:2195ec8bc9ff | 582 | } |
ThomasBGill | 13:2195ec8bc9ff | 583 | |
ThomasBGill | 15:05a227f970c2 | 584 | void GameOver() |
ThomasBGill | 15:05a227f970c2 | 585 | { |
ThomasBGill | 16:a26d7519830e | 586 | lcd.inverseMode(); |
ThomasBGill | 15:05a227f970c2 | 587 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 588 | lcd.printString("GAME OVER", 12, 2); |
ThomasBGill | 15:05a227f970c2 | 589 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 590 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 591 | Sleep(); |
ThomasBGill | 16:a26d7519830e | 592 | lcd.normalMode(); |
ThomasBGill | 15:05a227f970c2 | 593 | MainMenu(); |
ThomasBGill | 15:05a227f970c2 | 594 | } |
ThomasBGill | 15:05a227f970c2 | 595 | |
ThomasBGill | 16:a26d7519830e | 596 | void MonsterAttack(int m) |
ThomasBGill | 16:a26d7519830e | 597 | { |
ThomasBGill | 16:a26d7519830e | 598 | if(rand()%100 + 1 < EnemyList[m].EHit) { //If monster hits and isn't dead |
ThomasBGill | 16:a26d7519830e | 599 | |
ThomasBGill | 16:a26d7519830e | 600 | int damage = EnemyList[m].EDamage - ItemList[pa].ItemValue + rand()%3 - rand()%3; //Calculate damage |
ThomasBGill | 16:a26d7519830e | 601 | if (damage < 0) { |
ThomasBGill | 16:a26d7519830e | 602 | damage = 0; |
ThomasBGill | 16:a26d7519830e | 603 | } |
ThomasBGill | 16:a26d7519830e | 604 | ph = ph - damage; //Apply damage and calculate the monster's health |
ThomasBGill | 16:a26d7519830e | 605 | |
ThomasBGill | 16:a26d7519830e | 606 | char buffer[14]; |
ThomasBGill | 16:a26d7519830e | 607 | int write = sprintf(buffer,"%d damage",damage); // print formatted data to buffer |
ThomasBGill | 16:a26d7519830e | 608 | |
ThomasBGill | 16:a26d7519830e | 609 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 610 | lcd.printString(EnemyList[m].EName, 0 ,1); |
ThomasBGill | 16:a26d7519830e | 611 | lcd.printString("hits you for", 0 , 2); |
ThomasBGill | 16:a26d7519830e | 612 | lcd.printString(buffer, 0 , 3); |
ThomasBGill | 16:a26d7519830e | 613 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 614 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 615 | Sleep(); |
ThomasBGill | 16:a26d7519830e | 616 | |
ThomasBGill | 16:a26d7519830e | 617 | } else { //You dodge |
ThomasBGill | 16:a26d7519830e | 618 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 619 | lcd.printString("You dodge the", 0 ,1); |
ThomasBGill | 16:a26d7519830e | 620 | lcd.printString("monster's", 0 , 2); |
ThomasBGill | 16:a26d7519830e | 621 | lcd.printString("attack", 0 , 3); |
ThomasBGill | 16:a26d7519830e | 622 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 623 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 624 | Sleep(); |
ThomasBGill | 16:a26d7519830e | 625 | } |
ThomasBGill | 16:a26d7519830e | 626 | if(ph <= 0) { //Check if player is dead |
ThomasBGill | 16:a26d7519830e | 627 | GameOver(); |
ThomasBGill | 16:a26d7519830e | 628 | } |
ThomasBGill | 16:a26d7519830e | 629 | |
ThomasBGill | 16:a26d7519830e | 630 | } |
ThomasBGill | 16:a26d7519830e | 631 | |
ThomasBGill | 13:2195ec8bc9ff | 632 | void Fight() |
ThomasBGill | 13:2195ec8bc9ff | 633 | { |
ThomasBGill | 18:98ea2b787894 | 634 | int m = rand()%(level+1); |
ThomasBGill | 13:2195ec8bc9ff | 635 | |
ThomasBGill | 13:2195ec8bc9ff | 636 | int mh = EnemyList[m].EHealth; |
ThomasBGill | 13:2195ec8bc9ff | 637 | |
ThomasBGill | 13:2195ec8bc9ff | 638 | lcd.clear(); |
ThomasBGill | 13:2195ec8bc9ff | 639 | lcd.printString("FIGHT!", 24, 2); |
ThomasBGill | 13:2195ec8bc9ff | 640 | |
ThomasBGill | 13:2195ec8bc9ff | 641 | for(int i = 0; i<5; i++) { |
ThomasBGill | 13:2195ec8bc9ff | 642 | lcd.inverseMode(); |
ThomasBGill | 13:2195ec8bc9ff | 643 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 644 | wait(0.2); |
ThomasBGill | 13:2195ec8bc9ff | 645 | lcd.normalMode(); |
ThomasBGill | 13:2195ec8bc9ff | 646 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 647 | wait(0.2); |
ThomasBGill | 13:2195ec8bc9ff | 648 | } |
ThomasBGill | 13:2195ec8bc9ff | 649 | |
ThomasBGill | 13:2195ec8bc9ff | 650 | bool menu = 1; |
ThomasBGill | 13:2195ec8bc9ff | 651 | |
ThomasBGill | 13:2195ec8bc9ff | 652 | while(1) { |
ThomasBGill | 13:2195ec8bc9ff | 653 | ActFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 654 | StartFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 655 | DirFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 656 | |
ThomasBGill | 13:2195ec8bc9ff | 657 | lcd.clear(); |
ThomasBGill | 13:2195ec8bc9ff | 658 | |
ThomasBGill | 13:2195ec8bc9ff | 659 | lcd.printString(EnemyList[m].EName, 0, 0); |
ThomasBGill | 13:2195ec8bc9ff | 660 | char buffer1[14]; |
ThomasBGill | 13:2195ec8bc9ff | 661 | int write = sprintf(buffer1,"%d/%d",mh, EnemyList[m].EHealth); // print formatted data to buffer |
ThomasBGill | 13:2195ec8bc9ff | 662 | lcd.printString(buffer1, 54, 0); |
ThomasBGill | 13:2195ec8bc9ff | 663 | |
ThomasBGill | 13:2195ec8bc9ff | 664 | lcd.printString("You", 0, 2); |
ThomasBGill | 13:2195ec8bc9ff | 665 | char buffer2[14]; |
ThomasBGill | 13:2195ec8bc9ff | 666 | write = sprintf(buffer2,"%d/15",ph); // print formatted data to buffer |
ThomasBGill | 13:2195ec8bc9ff | 667 | lcd.printString(buffer2, 54, 2); |
ThomasBGill | 13:2195ec8bc9ff | 668 | |
ThomasBGill | 13:2195ec8bc9ff | 669 | if(menu) { |
ThomasBGill | 13:2195ec8bc9ff | 670 | lcd.printString("Fight <", 0, 4); |
ThomasBGill | 13:2195ec8bc9ff | 671 | lcd.printString("Run", 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 672 | } else { |
ThomasBGill | 13:2195ec8bc9ff | 673 | lcd.printString("Fight", 0, 4); |
ThomasBGill | 13:2195ec8bc9ff | 674 | lcd.printString("Run <", 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 675 | } |
ThomasBGill | 13:2195ec8bc9ff | 676 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 677 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 678 | |
ThomasBGill | 13:2195ec8bc9ff | 679 | if(DirFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 680 | DirFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 681 | menu = !menu; |
ThomasBGill | 13:2195ec8bc9ff | 682 | } |
ThomasBGill | 13:2195ec8bc9ff | 683 | if(ActFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 684 | ActFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 685 | if(menu) { //Fight |
ThomasBGill | 13:2195ec8bc9ff | 686 | //Hit monster |
ThomasBGill | 13:2195ec8bc9ff | 687 | if(rand()%100 + 1 > EnemyList[m].EDodge) { //If monster doesn't dodge |
ThomasBGill | 13:2195ec8bc9ff | 688 | |
ThomasBGill | 13:2195ec8bc9ff | 689 | int damage = ItemList[pw].ItemValue - EnemyList[m].EArmour + rand()%3 - rand()%3; //Calculate damage |
ThomasBGill | 15:05a227f970c2 | 690 | if (damage < 0) { |
ThomasBGill | 15:05a227f970c2 | 691 | damage = 0; |
ThomasBGill | 13:2195ec8bc9ff | 692 | } |
ThomasBGill | 15:05a227f970c2 | 693 | mh = mh - damage; //Apply damage and calculate the monster's health |
ThomasBGill | 15:05a227f970c2 | 694 | |
ThomasBGill | 15:05a227f970c2 | 695 | char buffer3[14]; |
ThomasBGill | 15:05a227f970c2 | 696 | write = sprintf(buffer3,"for %d damage",damage); // print formatted data to buffer |
ThomasBGill | 15:05a227f970c2 | 697 | |
ThomasBGill | 15:05a227f970c2 | 698 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 699 | lcd.printString("You hit the", 0 , 1); |
ThomasBGill | 16:a26d7519830e | 700 | lcd.printString(EnemyList[m].EName, 0 ,2); |
ThomasBGill | 16:a26d7519830e | 701 | lcd.printString(buffer3, 0, 3); |
ThomasBGill | 15:05a227f970c2 | 702 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 703 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 704 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 705 | |
ThomasBGill | 15:05a227f970c2 | 706 | } else { //Monster dodges |
ThomasBGill | 15:05a227f970c2 | 707 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 708 | lcd.printString(EnemyList[m].EName, 0 ,1); |
ThomasBGill | 16:a26d7519830e | 709 | lcd.printString("dodges your", 0 , 2); |
ThomasBGill | 16:a26d7519830e | 710 | lcd.printString("attack", 0 , 3); |
ThomasBGill | 15:05a227f970c2 | 711 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 712 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 713 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 714 | } |
ThomasBGill | 13:2195ec8bc9ff | 715 | |
ThomasBGill | 16:a26d7519830e | 716 | if(mh <= 0) { //Check if monster is dead |
ThomasBGill | 13:2195ec8bc9ff | 717 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 718 | lcd.printString("You win!", 18, 2); |
ThomasBGill | 13:2195ec8bc9ff | 719 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 720 | wait(1.0); |
ThomasBGill | 13:2195ec8bc9ff | 721 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 722 | break; |
ThomasBGill | 13:2195ec8bc9ff | 723 | } |
ThomasBGill | 13:2195ec8bc9ff | 724 | |
ThomasBGill | 16:a26d7519830e | 725 | MonsterAttack(m); |
ThomasBGill | 16:a26d7519830e | 726 | |
ThomasBGill | 13:2195ec8bc9ff | 727 | |
ThomasBGill | 16:a26d7519830e | 728 | } else { //Run away |
ThomasBGill | 15:05a227f970c2 | 729 | |
ThomasBGill | 16:a26d7519830e | 730 | int b = rand()%5; |
ThomasBGill | 16:a26d7519830e | 731 | |
ThomasBGill | 16:a26d7519830e | 732 | if(b == 0) { //Monster blocks the path |
ThomasBGill | 15:05a227f970c2 | 733 | |
ThomasBGill | 15:05a227f970c2 | 734 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 735 | lcd.printString("You try to run", 0, 0); |
ThomasBGill | 16:a26d7519830e | 736 | lcd.printString("away but the", 0, 1); |
ThomasBGill | 16:a26d7519830e | 737 | lcd.printString("monster blocks", 0, 2); |
ThomasBGill | 16:a26d7519830e | 738 | lcd.printString("the path", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 739 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 740 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 741 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 742 | |
ThomasBGill | 16:a26d7519830e | 743 | MonsterAttack(m); |
ThomasBGill | 16:a26d7519830e | 744 | |
ThomasBGill | 16:a26d7519830e | 745 | } else { |
ThomasBGill | 16:a26d7519830e | 746 | |
ThomasBGill | 16:a26d7519830e | 747 | int s = rand()%100 + 1; |
ThomasBGill | 16:a26d7519830e | 748 | |
ThomasBGill | 16:a26d7519830e | 749 | if(s > EnemyList[m].ESpd) { //If you outspeed monster |
ThomasBGill | 16:a26d7519830e | 750 | |
ThomasBGill | 16:a26d7519830e | 751 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 752 | lcd.printString("You run away", 6, 2); |
ThomasBGill | 16:a26d7519830e | 753 | lcd.refresh(); |
ThomasBGill | 17:8790dd599b25 | 754 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 755 | Sleep(); |
ThomasBGill | 16:a26d7519830e | 756 | break; |
ThomasBGill | 16:a26d7519830e | 757 | |
ThomasBGill | 16:a26d7519830e | 758 | } else { |
ThomasBGill | 16:a26d7519830e | 759 | |
ThomasBGill | 16:a26d7519830e | 760 | lcd.clear(); |
ThomasBGill | 16:a26d7519830e | 761 | lcd.printString("You try to run", 0, 0); |
ThomasBGill | 16:a26d7519830e | 762 | lcd.printString("away but the", 0, 1); |
ThomasBGill | 16:a26d7519830e | 763 | lcd.printString("monster", 0, 2); |
ThomasBGill | 16:a26d7519830e | 764 | lcd.printString("catches up to", 0, 3); |
ThomasBGill | 16:a26d7519830e | 765 | lcd.printString("you", 0, 4); |
ThomasBGill | 16:a26d7519830e | 766 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 767 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 768 | Sleep(); |
ThomasBGill | 16:a26d7519830e | 769 | |
ThomasBGill | 16:a26d7519830e | 770 | MonsterAttack(m); |
ThomasBGill | 16:a26d7519830e | 771 | |
ThomasBGill | 16:a26d7519830e | 772 | } |
ThomasBGill | 8:ee857f0147aa | 773 | |
ThomasBGill | 9:3cad581b5419 | 774 | |
ThomasBGill | 16:a26d7519830e | 775 | } |
ThomasBGill | 13:2195ec8bc9ff | 776 | } |
ThomasBGill | 13:2195ec8bc9ff | 777 | } |
ThomasBGill | 13:2195ec8bc9ff | 778 | } |
ThomasBGill | 13:2195ec8bc9ff | 779 | } |
ThomasBGill | 13:2195ec8bc9ff | 780 | |
ThomasBGill | 13:2195ec8bc9ff | 781 | void Map() |
ThomasBGill | 13:2195ec8bc9ff | 782 | { |
ThomasBGill | 13:2195ec8bc9ff | 783 | lcd.clear(); |
ThomasBGill | 13:2195ec8bc9ff | 784 | DrawMap(); |
ThomasBGill | 13:2195ec8bc9ff | 785 | while(!StartFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 786 | FlashPlayerLocation(); |
ThomasBGill | 13:2195ec8bc9ff | 787 | } |
ThomasBGill | 13:2195ec8bc9ff | 788 | StartFlag = 0; |
ThomasBGill | 14:55802ce40285 | 789 | ActFlag = 0; |
ThomasBGill | 14:55802ce40285 | 790 | DirFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 791 | } |
ThomasBGill | 13:2195ec8bc9ff | 792 | |
ThomasBGill | 13:2195ec8bc9ff | 793 | |
ThomasBGill | 13:2195ec8bc9ff | 794 | void Inventory() |
ThomasBGill | 13:2195ec8bc9ff | 795 | { |
ThomasBGill | 13:2195ec8bc9ff | 796 | lcd.clear(); |
ThomasBGill | 13:2195ec8bc9ff | 797 | lcd.printString("Armour:", 0, 0); |
ThomasBGill | 13:2195ec8bc9ff | 798 | lcd.printString(ItemList[pa].ItemName, 0, 1); |
ThomasBGill | 13:2195ec8bc9ff | 799 | char buffer1[14]; |
ThomasBGill | 13:2195ec8bc9ff | 800 | int write = sprintf(buffer1,"+%d Armour", ItemList[pa].ItemValue); // print formatted data to buffer |
ThomasBGill | 13:2195ec8bc9ff | 801 | lcd.printString(buffer1, 0, 2); |
ThomasBGill | 13:2195ec8bc9ff | 802 | |
ThomasBGill | 13:2195ec8bc9ff | 803 | lcd.printString("Weapon:", 0, 3); |
ThomasBGill | 13:2195ec8bc9ff | 804 | lcd.printString(ItemList[pw].ItemName, 0, 4); |
ThomasBGill | 13:2195ec8bc9ff | 805 | char buffer2[14]; |
ThomasBGill | 13:2195ec8bc9ff | 806 | write = sprintf(buffer2,"+%d Damage", ItemList[pw].ItemValue); // print formatted data to buffer |
ThomasBGill | 13:2195ec8bc9ff | 807 | lcd.printString(buffer2, 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 808 | lcd.refresh(); |
ThomasBGill | 14:55802ce40285 | 809 | |
ThomasBGill | 14:55802ce40285 | 810 | while(1) { |
ThomasBGill | 14:55802ce40285 | 811 | Sleep(); |
ThomasBGill | 14:55802ce40285 | 812 | |
ThomasBGill | 14:55802ce40285 | 813 | if(ActFlag) { |
ThomasBGill | 14:55802ce40285 | 814 | ActFlag = 0; |
ThomasBGill | 14:55802ce40285 | 815 | } |
ThomasBGill | 14:55802ce40285 | 816 | if(DirFlag) { |
ThomasBGill | 14:55802ce40285 | 817 | DirFlag = 0; |
ThomasBGill | 14:55802ce40285 | 818 | break; |
ThomasBGill | 14:55802ce40285 | 819 | } |
ThomasBGill | 14:55802ce40285 | 820 | if(StartFlag) { |
ThomasBGill | 14:55802ce40285 | 821 | StartFlag = 0; |
ThomasBGill | 14:55802ce40285 | 822 | break; |
ThomasBGill | 14:55802ce40285 | 823 | } |
ThomasBGill | 14:55802ce40285 | 824 | } |
ThomasBGill | 14:55802ce40285 | 825 | } |
ThomasBGill | 14:55802ce40285 | 826 | |
ThomasBGill | 14:55802ce40285 | 827 | void MapLegend() |
ThomasBGill | 14:55802ce40285 | 828 | { |
ThomasBGill | 14:55802ce40285 | 829 | lcd.clear(); |
ThomasBGill | 14:55802ce40285 | 830 | lcd.printString("@ Player", 0 ,0); |
ThomasBGill | 14:55802ce40285 | 831 | lcd.printString("# Wall", 0, 1); |
ThomasBGill | 14:55802ce40285 | 832 | lcd.printString(". Floor", 0, 2); |
ThomasBGill | 14:55802ce40285 | 833 | lcd.printString("= Chest", 0, 3); |
ThomasBGill | 14:55802ce40285 | 834 | lcd.printString("/ Open Chest", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 835 | |
ThomasBGill | 14:55802ce40285 | 836 | |
ThomasBGill | 14:55802ce40285 | 837 | while(1) { |
ThomasBGill | 14:55802ce40285 | 838 | Sleep(); |
ThomasBGill | 14:55802ce40285 | 839 | |
ThomasBGill | 14:55802ce40285 | 840 | if(ActFlag) { |
ThomasBGill | 14:55802ce40285 | 841 | ActFlag = 0; |
ThomasBGill | 14:55802ce40285 | 842 | } |
ThomasBGill | 14:55802ce40285 | 843 | if(DirFlag) { |
ThomasBGill | 14:55802ce40285 | 844 | DirFlag = 0; |
ThomasBGill | 14:55802ce40285 | 845 | break; |
ThomasBGill | 14:55802ce40285 | 846 | } |
ThomasBGill | 14:55802ce40285 | 847 | if(StartFlag) { |
ThomasBGill | 14:55802ce40285 | 848 | StartFlag = 0; |
ThomasBGill | 14:55802ce40285 | 849 | break; |
ThomasBGill | 14:55802ce40285 | 850 | } |
ThomasBGill | 14:55802ce40285 | 851 | } |
ThomasBGill | 8:ee857f0147aa | 852 | } |
ThomasBGill | 8:ee857f0147aa | 853 | |
ThomasBGill | 9:3cad581b5419 | 854 | void StartMenu() |
ThomasBGill | 9:3cad581b5419 | 855 | { |
ThomasBGill | 13:2195ec8bc9ff | 856 | int menu = 0; |
ThomasBGill | 9:3cad581b5419 | 857 | |
ThomasBGill | 14:55802ce40285 | 858 | char buffer[14]; |
ThomasBGill | 14:55802ce40285 | 859 | int write = sprintf(buffer,"Health %d/15",ph); // print formatted data to buffer |
ThomasBGill | 14:55802ce40285 | 860 | |
ThomasBGill | 14:55802ce40285 | 861 | |
ThomasBGill | 13:2195ec8bc9ff | 862 | while(1) { |
ThomasBGill | 13:2195ec8bc9ff | 863 | if(menu == 0) { |
ThomasBGill | 13:2195ec8bc9ff | 864 | lcd.clear(); |
ThomasBGill | 14:55802ce40285 | 865 | lcd.printString(buffer, 0, 0); |
ThomasBGill | 14:55802ce40285 | 866 | lcd.printString("Map <", 0, 2); |
ThomasBGill | 14:55802ce40285 | 867 | lcd.printString("Map Legend", 0, 3); |
ThomasBGill | 14:55802ce40285 | 868 | lcd.printString("Inventory", 0, 4); |
ThomasBGill | 14:55802ce40285 | 869 | lcd.printString("Continue", 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 870 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 871 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 872 | } else if (menu == 1) { |
ThomasBGill | 13:2195ec8bc9ff | 873 | lcd.clear(); |
ThomasBGill | 14:55802ce40285 | 874 | lcd.printString(buffer, 0, 0); |
ThomasBGill | 14:55802ce40285 | 875 | lcd.printString("Map", 0, 2); |
ThomasBGill | 14:55802ce40285 | 876 | lcd.printString("Map Legend <", 0, 3); |
ThomasBGill | 14:55802ce40285 | 877 | lcd.printString("Inventory", 0, 4); |
ThomasBGill | 14:55802ce40285 | 878 | lcd.printString("Continue", 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 879 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 880 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 881 | } else if (menu == 2) { |
ThomasBGill | 13:2195ec8bc9ff | 882 | lcd.clear(); |
ThomasBGill | 14:55802ce40285 | 883 | lcd.printString(buffer, 0, 0); |
ThomasBGill | 14:55802ce40285 | 884 | lcd.printString("Map", 0, 2); |
ThomasBGill | 14:55802ce40285 | 885 | lcd.printString("Map Legend", 0, 3); |
ThomasBGill | 14:55802ce40285 | 886 | lcd.printString("Inventory <", 0, 4); |
ThomasBGill | 14:55802ce40285 | 887 | lcd.printString("Continue", 0, 5); |
ThomasBGill | 14:55802ce40285 | 888 | lcd.refresh(); |
ThomasBGill | 14:55802ce40285 | 889 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 890 | } else if (menu == 3) { |
ThomasBGill | 14:55802ce40285 | 891 | lcd.clear(); |
ThomasBGill | 14:55802ce40285 | 892 | lcd.printString(buffer, 0, 0); |
ThomasBGill | 14:55802ce40285 | 893 | lcd.printString("Map", 0, 2); |
ThomasBGill | 14:55802ce40285 | 894 | lcd.printString("Map Legend", 0, 3); |
ThomasBGill | 14:55802ce40285 | 895 | lcd.printString("Inventory", 0, 4); |
ThomasBGill | 14:55802ce40285 | 896 | lcd.printString("Continue <", 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 897 | lcd.refresh(); |
ThomasBGill | 13:2195ec8bc9ff | 898 | Sleep(); |
ThomasBGill | 9:3cad581b5419 | 899 | } |
ThomasBGill | 13:2195ec8bc9ff | 900 | |
ThomasBGill | 13:2195ec8bc9ff | 901 | if(DirFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 902 | DirFlag = 0; |
ThomasBGill | 14:55802ce40285 | 903 | if((Down || Right) && menu < 3) { |
ThomasBGill | 13:2195ec8bc9ff | 904 | menu++; |
ThomasBGill | 13:2195ec8bc9ff | 905 | } else if((Up ||Left) && menu > 0) |
ThomasBGill | 13:2195ec8bc9ff | 906 | menu--; |
ThomasBGill | 13:2195ec8bc9ff | 907 | } |
ThomasBGill | 13:2195ec8bc9ff | 908 | if(ActFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 909 | ActFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 910 | if(menu == 0) { |
ThomasBGill | 13:2195ec8bc9ff | 911 | Map(); |
ThomasBGill | 13:2195ec8bc9ff | 912 | } else if(menu == 1) { |
ThomasBGill | 14:55802ce40285 | 913 | MapLegend(); |
ThomasBGill | 14:55802ce40285 | 914 | } else if(menu == 2) { |
ThomasBGill | 13:2195ec8bc9ff | 915 | Inventory(); |
ThomasBGill | 13:2195ec8bc9ff | 916 | } else { |
ThomasBGill | 13:2195ec8bc9ff | 917 | break; |
ThomasBGill | 13:2195ec8bc9ff | 918 | } |
ThomasBGill | 13:2195ec8bc9ff | 919 | } |
ThomasBGill | 16:a26d7519830e | 920 | if(StartFlag) { |
ThomasBGill | 16:a26d7519830e | 921 | StartFlag = 0; |
ThomasBGill | 16:a26d7519830e | 922 | } |
ThomasBGill | 9:3cad581b5419 | 923 | } |
ThomasBGill | 10:59c874d006ab | 924 | } |
ThomasBGill | 9:3cad581b5419 | 925 | |
ThomasBGill | 13:2195ec8bc9ff | 926 | |
ThomasBGill | 10:59c874d006ab | 927 | void Intro() |
ThomasBGill | 10:59c874d006ab | 928 | { |
ThomasBGill | 10:59c874d006ab | 929 | lcd.clear(); |
ThomasBGill | 10:59c874d006ab | 930 | lcd.printString("TBG RPG", 20, 2); |
ThomasBGill | 10:59c874d006ab | 931 | lcd.refresh(); |
ThomasBGill | 10:59c874d006ab | 932 | wait(1.0); |
ThomasBGill | 10:59c874d006ab | 933 | } |
ThomasBGill | 10:59c874d006ab | 934 | |
ThomasBGill | 10:59c874d006ab | 935 | void LevelScreen() |
ThomasBGill | 10:59c874d006ab | 936 | { |
ThomasBGill | 12:30a242706847 | 937 | char buffer[14]; |
ThomasBGill | 12:30a242706847 | 938 | |
ThomasBGill | 12:30a242706847 | 939 | int write = sprintf(buffer,"Level %d",level); // print formatted data to buffer |
ThomasBGill | 11:b86a15d26de9 | 940 | |
ThomasBGill | 10:59c874d006ab | 941 | lcd.clear(); |
ThomasBGill | 10:59c874d006ab | 942 | lcd.printString(buffer, 20, 2); |
ThomasBGill | 10:59c874d006ab | 943 | lcd.refresh(); |
ThomasBGill | 10:59c874d006ab | 944 | wait(1.0); |
ThomasBGill | 10:59c874d006ab | 945 | |
ThomasBGill | 10:59c874d006ab | 946 | } |
ThomasBGill | 10:59c874d006ab | 947 | |
ThomasBGill | 15:05a227f970c2 | 948 | void getItem() |
ThomasBGill | 12:30a242706847 | 949 | { |
ThomasBGill | 15:05a227f970c2 | 950 | |
ThomasBGill | 13:2195ec8bc9ff | 951 | int r = rand()%10; |
ThomasBGill | 12:30a242706847 | 952 | |
ThomasBGill | 12:30a242706847 | 953 | DirFlag = 0; |
ThomasBGill | 12:30a242706847 | 954 | |
ThomasBGill | 15:05a227f970c2 | 955 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 956 | lcd.printString("Do you want to", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 957 | lcd.printString("take the", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 958 | lcd.printString(ItemList[r].ItemName, 0, 3); |
ThomasBGill | 15:05a227f970c2 | 959 | lcd.printString("-Yes (Action)", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 960 | lcd.printString("-No (Other)", 0, 5); |
ThomasBGill | 15:05a227f970c2 | 961 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 962 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 963 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 964 | |
ThomasBGill | 15:05a227f970c2 | 965 | |
ThomasBGill | 15:05a227f970c2 | 966 | if(ActFlag) { |
ThomasBGill | 15:05a227f970c2 | 967 | |
ThomasBGill | 15:05a227f970c2 | 968 | ActFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 969 | |
ThomasBGill | 15:05a227f970c2 | 970 | if (r > 5) { |
ThomasBGill | 15:05a227f970c2 | 971 | pa = r; |
ThomasBGill | 15:05a227f970c2 | 972 | } else { |
ThomasBGill | 15:05a227f970c2 | 973 | pw = r; |
ThomasBGill | 15:05a227f970c2 | 974 | } |
ThomasBGill | 15:05a227f970c2 | 975 | |
ThomasBGill | 15:05a227f970c2 | 976 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 977 | lcd.printString("You take the", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 978 | lcd.printString(ItemList[r].ItemName, 0, 2); |
ThomasBGill | 15:05a227f970c2 | 979 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 980 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 981 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 982 | |
ThomasBGill | 16:a26d7519830e | 983 | } else { |
ThomasBGill | 16:a26d7519830e | 984 | |
ThomasBGill | 16:a26d7519830e | 985 | StartFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 986 | DirFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 987 | |
ThomasBGill | 13:2195ec8bc9ff | 988 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 989 | lcd.printString("You leave the", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 990 | lcd.printString(ItemList[r].ItemName, 0, 2); |
ThomasBGill | 15:05a227f970c2 | 991 | lcd.refresh(); |
ThomasBGill | 16:a26d7519830e | 992 | wait(1.0); |
ThomasBGill | 16:a26d7519830e | 993 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 994 | } |
ThomasBGill | 15:05a227f970c2 | 995 | } |
ThomasBGill | 15:05a227f970c2 | 996 | |
ThomasBGill | 15:05a227f970c2 | 997 | void BoobyTrap() |
ThomasBGill | 15:05a227f970c2 | 998 | { |
ThomasBGill | 15:05a227f970c2 | 999 | |
ThomasBGill | 15:05a227f970c2 | 1000 | int damage = rand()%5; |
ThomasBGill | 15:05a227f970c2 | 1001 | |
ThomasBGill | 15:05a227f970c2 | 1002 | if(damage != 0) { |
ThomasBGill | 15:05a227f970c2 | 1003 | |
ThomasBGill | 15:05a227f970c2 | 1004 | ph = ph - damage; |
ThomasBGill | 15:05a227f970c2 | 1005 | |
ThomasBGill | 15:05a227f970c2 | 1006 | char buffer[15]; |
ThomasBGill | 15:05a227f970c2 | 1007 | int write = sprintf(buffer, "You recive %d", damage); |
ThomasBGill | 15:05a227f970c2 | 1008 | |
ThomasBGill | 15:05a227f970c2 | 1009 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1010 | lcd.printString("The chest is", 0, 0); |
ThomasBGill | 16:a26d7519830e | 1011 | lcd.printString("booby trapped!", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 1012 | lcd.printString(buffer, 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1013 | lcd.printString("damage", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 1014 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1015 | wait(1.0); |
ThomasBGill | 13:2195ec8bc9ff | 1016 | Sleep(); |
ThomasBGill | 12:30a242706847 | 1017 | |
ThomasBGill | 15:05a227f970c2 | 1018 | //Check if player is dead |
ThomasBGill | 15:05a227f970c2 | 1019 | if(ph < 0) { |
ThomasBGill | 15:05a227f970c2 | 1020 | GameOver(); |
ThomasBGill | 15:05a227f970c2 | 1021 | } |
ThomasBGill | 15:05a227f970c2 | 1022 | } else { |
ThomasBGill | 12:30a242706847 | 1023 | |
ThomasBGill | 15:05a227f970c2 | 1024 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1025 | lcd.printString("The chest is", 0, 0); |
ThomasBGill | 16:a26d7519830e | 1026 | lcd.printString("booby trapped", 0, 1); |
ThomasBGill | 16:a26d7519830e | 1027 | lcd.printString("but the trap", 0, 2); |
ThomasBGill | 16:a26d7519830e | 1028 | lcd.printString("fails", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1029 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1030 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1031 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1032 | |
ThomasBGill | 15:05a227f970c2 | 1033 | } |
ThomasBGill | 15:05a227f970c2 | 1034 | } |
ThomasBGill | 13:2195ec8bc9ff | 1035 | |
ThomasBGill | 15:05a227f970c2 | 1036 | void RevealMap() |
ThomasBGill | 15:05a227f970c2 | 1037 | { |
ThomasBGill | 15:05a227f970c2 | 1038 | |
ThomasBGill | 15:05a227f970c2 | 1039 | for(int i = 0; i < 84; i++) { |
ThomasBGill | 15:05a227f970c2 | 1040 | for(int j = 0; j < 48; j++) { |
ThomasBGill | 15:05a227f970c2 | 1041 | |
ThomasBGill | 15:05a227f970c2 | 1042 | if(map[i][j] == FLOOR) { |
ThomasBGill | 15:05a227f970c2 | 1043 | map[i][j] = FLOOR_SEEN; |
ThomasBGill | 15:05a227f970c2 | 1044 | } |
ThomasBGill | 15:05a227f970c2 | 1045 | } |
ThomasBGill | 15:05a227f970c2 | 1046 | } |
ThomasBGill | 12:30a242706847 | 1047 | |
ThomasBGill | 15:05a227f970c2 | 1048 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1049 | lcd.printString("You find a map", 0, 0); |
ThomasBGill | 16:a26d7519830e | 1050 | lcd.printString("of the current", 0, 1); |
ThomasBGill | 16:a26d7519830e | 1051 | lcd.printString("level inside", 0, 2); |
ThomasBGill | 16:a26d7519830e | 1052 | lcd.printString("the chest", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1053 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1054 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1055 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1056 | } |
ThomasBGill | 15:05a227f970c2 | 1057 | |
ThomasBGill | 15:05a227f970c2 | 1058 | void Potion() |
ThomasBGill | 15:05a227f970c2 | 1059 | { |
ThomasBGill | 15:05a227f970c2 | 1060 | |
ThomasBGill | 15:05a227f970c2 | 1061 | int p = rand()%5; //0- Poison, 1- Teleport, Else- Full heal |
ThomasBGill | 15:05a227f970c2 | 1062 | |
ThomasBGill | 15:05a227f970c2 | 1063 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1064 | lcd.printString("You find a", 0, 0); |
ThomasBGill | 16:a26d7519830e | 1065 | lcd.printString("potion inside", 0, 1); |
ThomasBGill | 16:a26d7519830e | 1066 | lcd.printString("the chest", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 1067 | lcd.printString("Drink (Action)", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 1068 | lcd.printString("Leave (Other)", 0, 5); |
ThomasBGill | 15:05a227f970c2 | 1069 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1070 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1071 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1072 | |
ThomasBGill | 15:05a227f970c2 | 1073 | if(ActFlag) { //Potion drunk |
ThomasBGill | 15:05a227f970c2 | 1074 | ActFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 1075 | |
ThomasBGill | 15:05a227f970c2 | 1076 | if(p == 0) { //Poison |
ThomasBGill | 15:05a227f970c2 | 1077 | |
ThomasBGill | 15:05a227f970c2 | 1078 | int damage = rand()%4 + 1; |
ThomasBGill | 15:05a227f970c2 | 1079 | |
ThomasBGill | 15:05a227f970c2 | 1080 | ph = ph - damage; |
ThomasBGill | 15:05a227f970c2 | 1081 | |
ThomasBGill | 15:05a227f970c2 | 1082 | char buffer[15]; |
ThomasBGill | 15:05a227f970c2 | 1083 | int write = sprintf(buffer, "%d damage", damage); |
ThomasBGill | 13:2195ec8bc9ff | 1084 | |
ThomasBGill | 13:2195ec8bc9ff | 1085 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1086 | lcd.printString("You drink the", 0, 0); |
ThomasBGill | 15:05a227f970c2 | 1087 | lcd.printString("potion and", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 1088 | lcd.printString("suddenly feel", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 1089 | lcd.printString("ill.", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1090 | lcd.printString("You take", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 1091 | lcd.printString(buffer, 0, 5); |
ThomasBGill | 13:2195ec8bc9ff | 1092 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1093 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1094 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1095 | |
ThomasBGill | 15:05a227f970c2 | 1096 | //Check if player is dead |
ThomasBGill | 15:05a227f970c2 | 1097 | if(ph < 0) { |
ThomasBGill | 15:05a227f970c2 | 1098 | GameOver(); |
ThomasBGill | 15:05a227f970c2 | 1099 | } |
ThomasBGill | 15:05a227f970c2 | 1100 | } else if(p == 1) { //Teleport |
ThomasBGill | 12:30a242706847 | 1101 | |
ThomasBGill | 15:05a227f970c2 | 1102 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1103 | lcd.printString("You drink the", 0, 0); |
ThomasBGill | 15:05a227f970c2 | 1104 | lcd.printString("potion and", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 1105 | lcd.printString("suddenly feel", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 1106 | lcd.printString("your body", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1107 | lcd.printString("being", 0, 4); |
ThomasBGill | 15:05a227f970c2 | 1108 | lcd.printString("transported", 0, 5); |
ThomasBGill | 15:05a227f970c2 | 1109 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1110 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1111 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1112 | |
ThomasBGill | 15:05a227f970c2 | 1113 | GameLoop(); |
ThomasBGill | 15:05a227f970c2 | 1114 | |
ThomasBGill | 15:05a227f970c2 | 1115 | } else { //Full heal |
ThomasBGill | 15:05a227f970c2 | 1116 | |
ThomasBGill | 15:05a227f970c2 | 1117 | ph = 15; |
ThomasBGill | 13:2195ec8bc9ff | 1118 | |
ThomasBGill | 13:2195ec8bc9ff | 1119 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1120 | lcd.printString("You drink the", 0, 0); |
ThomasBGill | 15:05a227f970c2 | 1121 | lcd.printString("potion and", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 1122 | lcd.printString("suddenly feel", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 1123 | lcd.printString("all your", 0, 3); |
ThomasBGill | 15:05a227f970c2 | 1124 | lcd.printString("wounds heal", 0, 4); |
ThomasBGill | 13:2195ec8bc9ff | 1125 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1126 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1127 | Sleep(); |
ThomasBGill | 13:2195ec8bc9ff | 1128 | } |
ThomasBGill | 15:05a227f970c2 | 1129 | } else { //Leave the potion |
ThomasBGill | 15:05a227f970c2 | 1130 | DirFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 1131 | StartFlag = 0; |
ThomasBGill | 15:05a227f970c2 | 1132 | lcd.clear(); |
ThomasBGill | 15:05a227f970c2 | 1133 | lcd.printString("You walk away", 0, 0); |
ThomasBGill | 15:05a227f970c2 | 1134 | lcd.printString("and leave the", 0, 1); |
ThomasBGill | 15:05a227f970c2 | 1135 | lcd.printString("potion", 0, 2); |
ThomasBGill | 15:05a227f970c2 | 1136 | lcd.refresh(); |
ThomasBGill | 15:05a227f970c2 | 1137 | wait(1.0); |
ThomasBGill | 15:05a227f970c2 | 1138 | Sleep(); |
ThomasBGill | 15:05a227f970c2 | 1139 | } |
ThomasBGill | 15:05a227f970c2 | 1140 | } |
ThomasBGill | 13:2195ec8bc9ff | 1141 | |
ThomasBGill | 15:05a227f970c2 | 1142 | void Chest() |
ThomasBGill | 15:05a227f970c2 | 1143 | { |
ThomasBGill | 15:05a227f970c2 | 1144 | int c = rand()%4; //0- Item, 1- Booby trap, 2- Map, Else- Potion |
ThomasBGill | 13:2195ec8bc9ff | 1145 | |
ThomasBGill | 15:05a227f970c2 | 1146 | if(c == 0) { |
ThomasBGill | 15:05a227f970c2 | 1147 | getItem(); |
ThomasBGill | 15:05a227f970c2 | 1148 | } else if(c == 1) { |
ThomasBGill | 15:05a227f970c2 | 1149 | BoobyTrap(); |
ThomasBGill | 15:05a227f970c2 | 1150 | } else if(c == 2) { |
ThomasBGill | 15:05a227f970c2 | 1151 | RevealMap(); |
ThomasBGill | 15:05a227f970c2 | 1152 | } else { |
ThomasBGill | 15:05a227f970c2 | 1153 | Potion(); |
ThomasBGill | 12:30a242706847 | 1154 | } |
ThomasBGill | 15:05a227f970c2 | 1155 | |
ThomasBGill | 15:05a227f970c2 | 1156 | map[px][py] = CHEST_OPENED; |
ThomasBGill | 15:05a227f970c2 | 1157 | |
ThomasBGill | 12:30a242706847 | 1158 | } |
ThomasBGill | 12:30a242706847 | 1159 | |
ThomasBGill | 10:59c874d006ab | 1160 | void GameLoop() |
ThomasBGill | 10:59c874d006ab | 1161 | { |
ThomasBGill | 10:59c874d006ab | 1162 | while(1) { |
ThomasBGill | 10:59c874d006ab | 1163 | |
ThomasBGill | 11:b86a15d26de9 | 1164 | level++; |
ThomasBGill | 11:b86a15d26de9 | 1165 | |
ThomasBGill | 11:b86a15d26de9 | 1166 | World(); |
ThomasBGill | 11:b86a15d26de9 | 1167 | |
ThomasBGill | 11:b86a15d26de9 | 1168 | LevelScreen(); |
ThomasBGill | 19:1ab2d83ebffa | 1169 | |
ThomasBGill | 18:98ea2b787894 | 1170 | RevealMap(); |
ThomasBGill | 11:b86a15d26de9 | 1171 | |
ThomasBGill | 11:b86a15d26de9 | 1172 | while(1) { |
ThomasBGill | 11:b86a15d26de9 | 1173 | |
ThomasBGill | 16:a26d7519830e | 1174 | ActFlag = 0; |
ThomasBGill | 16:a26d7519830e | 1175 | StartFlag = 0; |
ThomasBGill | 16:a26d7519830e | 1176 | DirFlag = 0; |
ThomasBGill | 16:a26d7519830e | 1177 | |
ThomasBGill | 11:b86a15d26de9 | 1178 | PlayerCamera(); |
ThomasBGill | 12:30a242706847 | 1179 | |
ThomasBGill | 12:30a242706847 | 1180 | if(map[px][py] == CHEST) { |
ThomasBGill | 12:30a242706847 | 1181 | Chest(); |
ThomasBGill | 12:30a242706847 | 1182 | } |
ThomasBGill | 12:30a242706847 | 1183 | |
ThomasBGill | 12:30a242706847 | 1184 | if(px == exx && py == exy) { |
ThomasBGill | 12:30a242706847 | 1185 | |
ThomasBGill | 12:30a242706847 | 1186 | break; |
ThomasBGill | 12:30a242706847 | 1187 | |
ThomasBGill | 12:30a242706847 | 1188 | } |
ThomasBGill | 12:30a242706847 | 1189 | |
ThomasBGill | 11:b86a15d26de9 | 1190 | Sleep(); |
ThomasBGill | 10:59c874d006ab | 1191 | |
ThomasBGill | 10:59c874d006ab | 1192 | |
ThomasBGill | 11:b86a15d26de9 | 1193 | if(DirFlag) { |
ThomasBGill | 11:b86a15d26de9 | 1194 | |
ThomasBGill | 11:b86a15d26de9 | 1195 | DirFlag = 0; |
ThomasBGill | 10:59c874d006ab | 1196 | |
ThomasBGill | 11:b86a15d26de9 | 1197 | PlayerMove(); |
ThomasBGill | 13:2195ec8bc9ff | 1198 | |
ThomasBGill | 19:1ab2d83ebffa | 1199 | if(rand()%60 == 0) { |
ThomasBGill | 19:1ab2d83ebffa | 1200 | if(ph < 15) { |
ThomasBGill | 19:1ab2d83ebffa | 1201 | ph++; |
ThomasBGill | 19:1ab2d83ebffa | 1202 | } |
ThomasBGill | 19:1ab2d83ebffa | 1203 | } |
ThomasBGill | 19:1ab2d83ebffa | 1204 | |
ThomasBGill | 18:98ea2b787894 | 1205 | if(rand()%50 == 0) { |
ThomasBGill | 13:2195ec8bc9ff | 1206 | Fight(); |
ThomasBGill | 13:2195ec8bc9ff | 1207 | } |
ThomasBGill | 13:2195ec8bc9ff | 1208 | |
ThomasBGill | 11:b86a15d26de9 | 1209 | } |
ThomasBGill | 11:b86a15d26de9 | 1210 | if(StartFlag) { |
ThomasBGill | 10:59c874d006ab | 1211 | |
ThomasBGill | 11:b86a15d26de9 | 1212 | StartFlag = 0; |
ThomasBGill | 10:59c874d006ab | 1213 | |
ThomasBGill | 11:b86a15d26de9 | 1214 | StartMenu(); |
ThomasBGill | 11:b86a15d26de9 | 1215 | } |
ThomasBGill | 13:2195ec8bc9ff | 1216 | if(ActFlag) { |
ThomasBGill | 13:2195ec8bc9ff | 1217 | |
ThomasBGill | 13:2195ec8bc9ff | 1218 | ActFlag = 0; |
ThomasBGill | 13:2195ec8bc9ff | 1219 | } |
ThomasBGill | 10:59c874d006ab | 1220 | } |
ThomasBGill | 10:59c874d006ab | 1221 | } |
ThomasBGill | 10:59c874d006ab | 1222 | } |
ThomasBGill | 10:59c874d006ab | 1223 | |
ThomasBGill | 10:59c874d006ab | 1224 | void MainMenu() |
ThomasBGill | 10:59c874d006ab | 1225 | { |
ThomasBGill | 13:2195ec8bc9ff | 1226 | level = 0; |
ThomasBGill | 13:2195ec8bc9ff | 1227 | |
ThomasBGill | 13:2195ec8bc9ff | 1228 | //Player Health |
ThomasBGill | 13:2195ec8bc9ff | 1229 | ph = 15; |
ThomasBGill | 13:2195ec8bc9ff | 1230 | |
ThomasBGill | 13:2195ec8bc9ff | 1231 | //Player weapon |
ThomasBGill | 13:2195ec8bc9ff | 1232 | pw = 0; //0 to 4 |
ThomasBGill | 13:2195ec8bc9ff | 1233 | |
ThomasBGill | 13:2195ec8bc9ff | 1234 | //Player armour |
ThomasBGill | 13:2195ec8bc9ff | 1235 | pa = 5; //5 to 9 |
ThomasBGill | 13:2195ec8bc9ff | 1236 | |
ThomasBGill | 12:30a242706847 | 1237 | bool menu = 0; |
ThomasBGill | 10:59c874d006ab | 1238 | |
ThomasBGill | 10:59c874d006ab | 1239 | while(1) { |
ThomasBGill | 10:59c874d006ab | 1240 | lcd.clear(); |
ThomasBGill | 10:59c874d006ab | 1241 | if(menu == 0) { |
ThomasBGill | 10:59c874d006ab | 1242 | lcd.printString("New Game <", 20, 1); |
ThomasBGill | 10:59c874d006ab | 1243 | lcd.printString("Options",20,3); |
ThomasBGill | 10:59c874d006ab | 1244 | lcd.refresh(); |
ThomasBGill | 10:59c874d006ab | 1245 | Sleep(); |
ThomasBGill | 10:59c874d006ab | 1246 | } else { |
ThomasBGill | 10:59c874d006ab | 1247 | lcd.printString("New Game", 20, 1); |
ThomasBGill | 10:59c874d006ab | 1248 | lcd.printString("Options <",20,3); |
ThomasBGill | 10:59c874d006ab | 1249 | lcd.refresh(); |
ThomasBGill | 10:59c874d006ab | 1250 | Sleep(); |
ThomasBGill | 10:59c874d006ab | 1251 | } |
ThomasBGill | 10:59c874d006ab | 1252 | |
ThomasBGill | 10:59c874d006ab | 1253 | if(DirFlag) { |
ThomasBGill | 10:59c874d006ab | 1254 | |
ThomasBGill | 10:59c874d006ab | 1255 | DirFlag = 0; |
ThomasBGill | 10:59c874d006ab | 1256 | |
ThomasBGill | 10:59c874d006ab | 1257 | menu = !menu; |
ThomasBGill | 10:59c874d006ab | 1258 | } |
ThomasBGill | 13:2195ec8bc9ff | 1259 | if(ActFlag) { |
ThomasBGill | 10:59c874d006ab | 1260 | |
ThomasBGill | 10:59c874d006ab | 1261 | ActFlag = 0; |
ThomasBGill | 10:59c874d006ab | 1262 | |
ThomasBGill | 13:2195ec8bc9ff | 1263 | if(menu == 0) { |
ThomasBGill | 13:2195ec8bc9ff | 1264 | GameLoop(); |
ThomasBGill | 13:2195ec8bc9ff | 1265 | } |
ThomasBGill | 10:59c874d006ab | 1266 | } |
ThomasBGill | 10:59c874d006ab | 1267 | } |
ThomasBGill | 9:3cad581b5419 | 1268 | } |
ThomasBGill | 8:ee857f0147aa | 1269 | |
ThomasBGill | 0:9200b3c387ed | 1270 | int main() |
ThomasBGill | 0:9200b3c387ed | 1271 | { |
ThomasBGill | 1:0f774d41584c | 1272 | //Power Saving |
ThomasBGill | 1:0f774d41584c | 1273 | PHY_PowerDown (); |
ThomasBGill | 1:0f774d41584c | 1274 | int result = semihost_powerdown(); |
ThomasBGill | 1:0f774d41584c | 1275 | |
ThomasBGill | 10:59c874d006ab | 1276 | Up.rise(&DirPressed); |
ThomasBGill | 10:59c874d006ab | 1277 | Down.rise(&DirPressed); |
ThomasBGill | 10:59c874d006ab | 1278 | Right.rise(&DirPressed); |
ThomasBGill | 10:59c874d006ab | 1279 | Left.rise(&DirPressed); |
ThomasBGill | 9:3cad581b5419 | 1280 | Start.rise(&StartPressed); |
ThomasBGill | 10:59c874d006ab | 1281 | Act.rise(&ActPressed); |
ThomasBGill | 9:3cad581b5419 | 1282 | |
ThomasBGill | 1:0f774d41584c | 1283 | //Generate random seed |
ThomasBGill | 0:9200b3c387ed | 1284 | srand(Noise*1000000); |
ThomasBGill | 1:0f774d41584c | 1285 | |
ThomasBGill | 1:0f774d41584c | 1286 | //Initilize screen |
ThomasBGill | 0:9200b3c387ed | 1287 | lcd.init(); |
ThomasBGill | 8:ee857f0147aa | 1288 | |
ThomasBGill | 10:59c874d006ab | 1289 | Intro(); |
ThomasBGill | 9:3cad581b5419 | 1290 | |
ThomasBGill | 10:59c874d006ab | 1291 | MainMenu(); |
ThomasBGill | 10:59c874d006ab | 1292 | } |