Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Thu May 09 06:33:28 2019 +0000
Revision:
50:2c5cb92a5361
Parent:
49:3f83ed62d123
Child:
51:4d0cd75e7ed3
Room Engine fully commented;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 0:8e92b66a0755 1 /*
el17sm 0:8e92b66a0755 2 ELEC2645 Embedded Systems Project
el17sm 0:8e92b66a0755 3 School of Electronic & Electrical Engineering
el17sm 0:8e92b66a0755 4 University of Leeds
el17sm 0:8e92b66a0755 5 Name: Steven Mahasin
el17sm 0:8e92b66a0755 6 Username: el17sm
el17sm 0:8e92b66a0755 7 Student ID Number: 201192939
el17sm 0:8e92b66a0755 8 Date: 11/04/2019
el17sm 1:1fa7ecca8dfb 9 */
el17sm 46:f09711580d4a 10 #include "main.h"
el17sm 10:1a3499f6b583 11
el17sm 1:1fa7ecca8dfb 12 int main()
el17sm 1:1fa7ecca8dfb 13 {
el17sm 29:6b8411bb040a 14 // Initialize
el17sm 46:f09711580d4a 15 init();
el17sm 28:98848e6a77a2 16
el17sm 29:6b8411bb040a 17 while(1) { // Gameloop
el17sm 50:2c5cb92a5361 18 boss_room_exist = false; // Game initialize variables
el17sm 47:6e31b195ce3c 19 number_of_enemies_killed = 0;
el17sm 47:6e31b195ce3c 20 total_time = 0;
el17sm 47:6e31b195ce3c 21
el17sm 32:fe6359ef9916 22 title.main(lcd, gamepad, global_contrast);
el17sm 32:fe6359ef9916 23 srand(title.get_seed());
el17sm 31:ab24d028ddfd 24 player = new Player(39, 27);
el17sm 41:0697508a28ba 25 room_engine = new RoomEngine(global_contrast);
el17sm 31:ab24d028ddfd 26
el17sm 31:ab24d028ddfd 27 game_loop();
el17sm 50:2c5cb92a5361 28 game_unload(); // Deletion of player, rooms, roomengine
el17sm 31:ab24d028ddfd 29 }
el17sm 31:ab24d028ddfd 30 }
el17sm 31:ab24d028ddfd 31
el17sm 46:f09711580d4a 32 void init()
el17sm 46:f09711580d4a 33 {
el17sm 46:f09711580d4a 34 lcd.init();
el17sm 46:f09711580d4a 35 lcd.setContrast(global_contrast);
el17sm 46:f09711580d4a 36 gamepad.init();
el17sm 46:f09711580d4a 37 for (int j = 0; j < MAX_ROOMS_MAP_Y; j++){
el17sm 46:f09711580d4a 38 for (int i = 0; i < MAX_ROOMS_MAP_X; i++){
el17sm 46:f09711580d4a 39 valid_rooms[j][i] = false;
el17sm 46:f09711580d4a 40 }
el17sm 46:f09711580d4a 41 }
el17sm 46:f09711580d4a 42 }
el17sm 46:f09711580d4a 43
el17sm 31:ab24d028ddfd 44 void game_loop()
el17sm 31:ab24d028ddfd 45 {
el17sm 31:ab24d028ddfd 46 while(1) { // Floor Loop
el17sm 46:f09711580d4a 47 boss_room_number = 5 + rand() % 4; // Boss room appears after travelling 5-8 rooms
el17sm 46:f09711580d4a 48 boss_room_counter = 0;
el17sm 46:f09711580d4a 49 while(1) { // Room Loop
el17sm 50:2c5cb92a5361 50 room_entrance(); // Generation of new room, loading of room and entrance scene
el17sm 48:f7d9ae3e554d 51 while(room_engine->check_player_room_position() == INSIDE) { // actions inside the Room
el17sm 31:ab24d028ddfd 52 room_engine->read_input(gamepad);
el17sm 47:6e31b195ce3c 53 room_engine->update(number_of_enemies_killed);
el17sm 31:ab24d028ddfd 54 room_engine->render(lcd, gamepad);
el17sm 46:f09711580d4a 55 minimap_detection();
el17sm 50:2c5cb92a5361 56 total_time++; // Incrementing time score
el17sm 48:f7d9ae3e554d 57 if (player->get_hp() <= 0) {goto gameover;} // gameover if player health depleted
el17sm 48:f7d9ae3e554d 58 if ((rooms[room_y][room_x]->get_room_type() == 10) && !(rooms[room_y][room_x]->enemies_exist())){goto winner;} // wins game if room is a boss room, and the boss is dead
el17sm 29:6b8411bb040a 59 }
el17sm 50:2c5cb92a5361 60 room_exit(); // Exit scene, deletion of existing entities and update of room coordinates
el17sm 31:ab24d028ddfd 61 }
el17sm 31:ab24d028ddfd 62 }
el17sm 48:f7d9ae3e554d 63 gameover : { game_over(); goto displaystats;}
el17sm 48:f7d9ae3e554d 64 winner : { win(); goto displaystats;}
el17sm 48:f7d9ae3e554d 65 displaystats : { display_stats();}
el17sm 48:f7d9ae3e554d 66 }
el17sm 48:f7d9ae3e554d 67
el17sm 48:f7d9ae3e554d 68 void room_entrance()
el17sm 48:f7d9ae3e554d 69 {
el17sm 50:2c5cb92a5361 70 update_room_coords(); // Accessor to room_engine room coords
el17sm 48:f7d9ae3e554d 71 if (!valid_rooms[room_y][room_x]){generate_room();} // generate a new room if player enters a nonexistent room
el17sm 48:f7d9ae3e554d 72 room_engine->load(player, rooms[room_y][room_x]);
el17sm 48:f7d9ae3e554d 73 room_engine->entrance_scene(lcd, gamepad);
el17sm 48:f7d9ae3e554d 74 }
el17sm 48:f7d9ae3e554d 75
el17sm 48:f7d9ae3e554d 76 void room_exit()
el17sm 48:f7d9ae3e554d 77 {
el17sm 48:f7d9ae3e554d 78 room_engine->exit_scene(lcd, gamepad);
el17sm 48:f7d9ae3e554d 79 rooms[room_y][room_x]->unload();
el17sm 48:f7d9ae3e554d 80 player->delete_bullets();
el17sm 50:2c5cb92a5361 81 room_engine->update_current_room(); // Increments room coord
el17sm 31:ab24d028ddfd 82 }
el17sm 29:6b8411bb040a 83
el17sm 46:f09711580d4a 84 void generate_room()
el17sm 46:f09711580d4a 85 {
el17sm 50:2c5cb92a5361 86 valid_rooms[room_y][room_x] = true; // Sets the room coord to be valid
el17sm 50:2c5cb92a5361 87 if (boss_room_counter == 0) { // if first room
el17sm 50:2c5cb92a5361 88 rooms[room_y][room_x] = new Room(0, 0); // no enemies
el17sm 46:f09711580d4a 89 rooms[room_y][room_x]->set_doorway(0, true);
el17sm 46:f09711580d4a 90 } else {
el17sm 50:2c5cb92a5361 91 rooms[room_y][room_x] = new Room(rand() % 4, 0); // random enemies (0-3)
el17sm 46:f09711580d4a 92 if (boss_room_counter < boss_room_number) {no_of_doorways = 2 + (rand() % 100 < 10) + (rand() % 100 < 10);} // 20% chance of adding doorways
el17sm 50:2c5cb92a5361 93 else {no_of_doorways = 1;} // If boss room exist, ensure all unexplored rooms branch out into a dead end
el17sm 46:f09711580d4a 94 while (count_doorways() < no_of_doorways) {
el17sm 46:f09711580d4a 95 rooms[room_y][room_x]->set_doorway(rand() % 4, true); // Setting random doorways until number of desired doorways
el17sm 46:f09711580d4a 96 }
el17sm 46:f09711580d4a 97 update_definite_doorways();
el17sm 50:2c5cb92a5361 98 for (int i = 0; i < 4; i++) { // Sets the definitive doorways
el17sm 46:f09711580d4a 99 if (cannot[i]){rooms[room_y][room_x]->set_doorway(i, false);}
el17sm 46:f09711580d4a 100 if (have_to[i]){rooms[room_y][room_x]->set_doorway(i, true);}
el17sm 46:f09711580d4a 101 }
el17sm 50:2c5cb92a5361 102 if ((boss_room_counter >= boss_room_number) && (!boss_room_exist)) { // Sets the doorway towards the boss room to be a boss doorway
el17sm 46:f09711580d4a 103 rooms[room_y][room_x]->set_boss_doorway(available_boss_room());
el17sm 46:f09711580d4a 104 boss_room_exist = true;
el17sm 46:f09711580d4a 105 }
el17sm 46:f09711580d4a 106 }
el17sm 46:f09711580d4a 107 boss_room_counter++;
el17sm 46:f09711580d4a 108 }
el17sm 46:f09711580d4a 109
el17sm 46:f09711580d4a 110 void update_room_coords()
el17sm 46:f09711580d4a 111 {
el17sm 46:f09711580d4a 112 room_y = room_engine->get_room_y();
el17sm 46:f09711580d4a 113 room_x = room_engine->get_room_x();
el17sm 46:f09711580d4a 114 }
el17sm 46:f09711580d4a 115
el17sm 48:f7d9ae3e554d 116 void minimap_detection()
el17sm 48:f7d9ae3e554d 117 {
el17sm 49:3f83ed62d123 118 while(gamepad.check_event(Gamepad::R_PRESSED)) {
el17sm 48:f7d9ae3e554d 119 lcd.clear();
el17sm 48:f7d9ae3e554d 120 for (int j = 0; j < MAX_ROOMS_MAP_Y; j++) {
el17sm 48:f7d9ae3e554d 121 for (int i = 0; i < MAX_ROOMS_MAP_X; i++) {
el17sm 48:f7d9ae3e554d 122 if (valid_rooms[j][i]) {
el17sm 50:2c5cb92a5361 123 draw_minimap(j,i);
el17sm 48:f7d9ae3e554d 124 }
el17sm 48:f7d9ae3e554d 125 }
el17sm 48:f7d9ae3e554d 126 }
el17sm 50:2c5cb92a5361 127 lcd.drawSpriteTransparent(33, 17, 15, 20, (char *)minimap_sprite[3]); // draws your current room
el17sm 48:f7d9ae3e554d 128 lcd.refresh();
el17sm 48:f7d9ae3e554d 129 wait_ms(1000/40);
el17sm 48:f7d9ae3e554d 130 };
el17sm 48:f7d9ae3e554d 131 }
el17sm 48:f7d9ae3e554d 132
el17sm 50:2c5cb92a5361 133 void draw_minimap(int j, int i)
el17sm 50:2c5cb92a5361 134 {
el17sm 50:2c5cb92a5361 135 lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[0]); // draws normal room
el17sm 50:2c5cb92a5361 136 if (rooms[j][i]->get_room_type() == 10) {
el17sm 50:2c5cb92a5361 137 lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[2]); // draws boss room
el17sm 50:2c5cb92a5361 138 } else if (rooms[j][i]->enemies_exist()) {
el17sm 50:2c5cb92a5361 139 lcd.drawSprite(33 + (i-room_x)*20, 17 + (j-room_y)*15, 15, 20, (char *)minimap_sprite[1]); // draws mob room
el17sm 50:2c5cb92a5361 140 }
el17sm 50:2c5cb92a5361 141 if (rooms[j][i]->get_doorway(0)) { // Drawing all doorways
el17sm 50:2c5cb92a5361 142 lcd.drawLine(42 + (i-room_x)*20, 17 + (j-room_y)*15, 43 + (i-room_x)*20, 17 + (j-room_y)*15, 1);
el17sm 50:2c5cb92a5361 143 }
el17sm 50:2c5cb92a5361 144 if (rooms[j][i]->get_doorway(1)) {
el17sm 50:2c5cb92a5361 145 lcd.drawLine(52 + (i-room_x)*20, 23 + (j-room_y)*15, 52 + (i-room_x)*20, 24 + (j-room_y)*15, 1);
el17sm 50:2c5cb92a5361 146 }
el17sm 50:2c5cb92a5361 147 if (rooms[j][i]->get_doorway(2)) {
el17sm 50:2c5cb92a5361 148 lcd.drawLine(42 + (i-room_x)*20, 31 + (j-room_y)*15, 43 + (i-room_x)*20, 31 + (j-room_y)*15, 1);
el17sm 50:2c5cb92a5361 149 }
el17sm 50:2c5cb92a5361 150 if (rooms[j][i]->get_doorway(3)) {
el17sm 50:2c5cb92a5361 151 lcd.drawLine(33 + (i-room_x)*20, 23 + (j-room_y)*15, 33 + (i-room_x)*20, 24 + (j-room_y)*15, 1);
el17sm 50:2c5cb92a5361 152 }
el17sm 50:2c5cb92a5361 153 }
el17sm 50:2c5cb92a5361 154
el17sm 48:f7d9ae3e554d 155 void game_over()
el17sm 48:f7d9ae3e554d 156 {
el17sm 48:f7d9ae3e554d 157 lcd.clear();
el17sm 48:f7d9ae3e554d 158 lcd.setContrast(global_contrast);
el17sm 49:3f83ed62d123 159 lcd.printString("Game Over", 0, 0);
el17sm 48:f7d9ae3e554d 160 }
el17sm 48:f7d9ae3e554d 161
el17sm 48:f7d9ae3e554d 162 void win()
el17sm 48:f7d9ae3e554d 163 {
el17sm 48:f7d9ae3e554d 164 lcd.clear();
el17sm 48:f7d9ae3e554d 165 lcd.setContrast(global_contrast);
el17sm 49:3f83ed62d123 166 lcd.printString("You won!", 0, 0);
el17sm 48:f7d9ae3e554d 167 }
el17sm 48:f7d9ae3e554d 168
el17sm 48:f7d9ae3e554d 169 void display_stats()
el17sm 48:f7d9ae3e554d 170 {
el17sm 49:3f83ed62d123 171 lcd.printString("Restart?", 0, 1);
el17sm 48:f7d9ae3e554d 172 lcd.printString("Enemies Killed:", 0, 2);
el17sm 48:f7d9ae3e554d 173 char kills[10];
el17sm 48:f7d9ae3e554d 174 sprintf(kills, "%d enemies", number_of_enemies_killed);
el17sm 48:f7d9ae3e554d 175 lcd.printString(kills, 0, 3);
el17sm 48:f7d9ae3e554d 176 lcd.printString("Time:", 0, 4);
el17sm 48:f7d9ae3e554d 177 char total_duration[10];
el17sm 48:f7d9ae3e554d 178 sprintf(total_duration, "%d seconds", (total_time/40));
el17sm 48:f7d9ae3e554d 179 lcd.printString(total_duration, 0, 5);
el17sm 48:f7d9ae3e554d 180 lcd.refresh();
el17sm 48:f7d9ae3e554d 181 while(gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 48:f7d9ae3e554d 182 }
el17sm 48:f7d9ae3e554d 183 wait(0.05);
el17sm 48:f7d9ae3e554d 184 while(!gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 48:f7d9ae3e554d 185 }
el17sm 48:f7d9ae3e554d 186 wait(0.05);
el17sm 48:f7d9ae3e554d 187 while(gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 48:f7d9ae3e554d 188 }
el17sm 48:f7d9ae3e554d 189 }
el17sm 48:f7d9ae3e554d 190
el17sm 48:f7d9ae3e554d 191 int available_boss_room()
el17sm 48:f7d9ae3e554d 192 {
el17sm 50:2c5cb92a5361 193 if (!valid_rooms[room_y - 1][room_x]){ // if any of the adjacent room is invalid, it is replaced with a boss room
el17sm 48:f7d9ae3e554d 194 rooms[room_y][room_x]->set_doorway(0, true);
el17sm 49:3f83ed62d123 195 set_boss_room(room_y - 1, room_x, 0);
el17sm 48:f7d9ae3e554d 196 return 0;
el17sm 48:f7d9ae3e554d 197 } else if (!valid_rooms[room_y][room_x + 1]){
el17sm 48:f7d9ae3e554d 198 rooms[room_y][room_x]->set_doorway(1, true);
el17sm 49:3f83ed62d123 199 set_boss_room(room_y, room_x + 1, 1);
el17sm 48:f7d9ae3e554d 200 return 1;
el17sm 48:f7d9ae3e554d 201 } else if (!valid_rooms[room_y + 1][room_x]){
el17sm 48:f7d9ae3e554d 202 rooms[room_y][room_x]->set_doorway(2, true);
el17sm 49:3f83ed62d123 203 set_boss_room(room_y + 1, room_x, 2);
el17sm 48:f7d9ae3e554d 204 return 2;
el17sm 48:f7d9ae3e554d 205 } else if (!valid_rooms[room_y][room_x - 1]){
el17sm 48:f7d9ae3e554d 206 rooms[room_y][room_x]->set_doorway(3, true);
el17sm 49:3f83ed62d123 207 set_boss_room(room_y, room_x - 1, 3);
el17sm 49:3f83ed62d123 208 return 3; }
el17sm 50:2c5cb92a5361 209 delete rooms[room_y - 1][room_x]; // if all adjacent room is valid, mutate the top room into a boss room (default case)
el17sm 49:3f83ed62d123 210 rooms[room_y][room_x]->set_doorway(3, true);
el17sm 49:3f83ed62d123 211 set_boss_room(room_y - 1, room_x, 0);
el17sm 48:f7d9ae3e554d 212 return 0;
el17sm 48:f7d9ae3e554d 213 }
el17sm 48:f7d9ae3e554d 214
el17sm 49:3f83ed62d123 215 void set_boss_room(int room_y, int room_x, int side)
el17sm 49:3f83ed62d123 216 {
el17sm 49:3f83ed62d123 217 valid_rooms[room_y][room_x] = true;
el17sm 49:3f83ed62d123 218 rooms[room_y][room_x] = new Room(0, 10);
el17sm 50:2c5cb92a5361 219 rooms[room_y][room_x]->set_doorway(opposite(side), true); // Sets a definite doorway on the side player comes from
el17sm 50:2c5cb92a5361 220 if ((opposite(side) != 0) && (valid_rooms[room_y - 1][room_x])){ // Deletes any existing doorways unless player entered from that side
el17sm 49:3f83ed62d123 221 if (rooms[room_y - 1][room_x]->get_doorway(2)){
el17sm 49:3f83ed62d123 222 rooms[room_y - 1][room_x]->set_doorway(2, false);
el17sm 49:3f83ed62d123 223 }}
el17sm 49:3f83ed62d123 224 if ((opposite(side) != 1) && (valid_rooms[room_y][room_x + 1])){
el17sm 49:3f83ed62d123 225 if (rooms[room_y][room_x + 1]->get_doorway(3)){
el17sm 49:3f83ed62d123 226 rooms[room_y][room_x + 1]->set_doorway(3, false);
el17sm 49:3f83ed62d123 227 }}
el17sm 49:3f83ed62d123 228 if ((opposite(side) != 2) && (valid_rooms[room_y + 1][room_x])){
el17sm 49:3f83ed62d123 229 if (rooms[room_y + 1][room_x]->get_doorway(0)){
el17sm 49:3f83ed62d123 230 rooms[room_y + 1][room_x]->set_doorway(0, false);
el17sm 49:3f83ed62d123 231 }}
el17sm 49:3f83ed62d123 232 if ((opposite(side) != 3) && (valid_rooms[room_y][room_x - 1])){
el17sm 49:3f83ed62d123 233 if (rooms[room_y][room_x - 1]->get_doorway(1)){
el17sm 49:3f83ed62d123 234 rooms[room_y][room_x - 1]->set_doorway(1, false);
el17sm 49:3f83ed62d123 235 }}
el17sm 49:3f83ed62d123 236 }
el17sm 49:3f83ed62d123 237
el17sm 48:f7d9ae3e554d 238 void game_unload()
el17sm 48:f7d9ae3e554d 239 {
el17sm 50:2c5cb92a5361 240 // Deletes every generated rooms
el17sm 48:f7d9ae3e554d 241 for (int i = 0; i < MAX_ROOMS_MAP_X; i++) {
el17sm 50:2c5cb92a5361 242 for (int j = 0; j < MAX_ROOMS_MAP_Y; j++) {
el17sm 50:2c5cb92a5361 243 if (valid_rooms[j][j]){
el17sm 50:2c5cb92a5361 244 delete rooms[j][i];
el17sm 50:2c5cb92a5361 245 valid_rooms[i][j] = false;
el17sm 48:f7d9ae3e554d 246 }
el17sm 48:f7d9ae3e554d 247 }
el17sm 50:2c5cb92a5361 248 }
el17sm 50:2c5cb92a5361 249 delete room_engine;
el17sm 50:2c5cb92a5361 250 delete player;
el17sm 48:f7d9ae3e554d 251 }
el17sm 48:f7d9ae3e554d 252
el17sm 48:f7d9ae3e554d 253 // Functions
el17sm 46:f09711580d4a 254 int opposite(int value)
el17sm 46:f09711580d4a 255 {
el17sm 46:f09711580d4a 256 if (value <= 1) {
el17sm 46:f09711580d4a 257 return value + 2;
el17sm 46:f09711580d4a 258 } else {
el17sm 46:f09711580d4a 259 return value - 2;
el17sm 46:f09711580d4a 260 }
el17sm 46:f09711580d4a 261 }
el17sm 46:f09711580d4a 262
el17sm 46:f09711580d4a 263 int count_doorways() // counts number of exisisting doorways
el17sm 46:f09711580d4a 264 {
el17sm 46:f09711580d4a 265 int count = 0;
el17sm 46:f09711580d4a 266 for (int i = 0; i < 4; i++){
el17sm 46:f09711580d4a 267 if (rooms[room_y][room_x]->get_doorway(i)) {
el17sm 46:f09711580d4a 268 count++;
el17sm 46:f09711580d4a 269 }
el17sm 46:f09711580d4a 270 }
el17sm 46:f09711580d4a 271 return count;
el17sm 46:f09711580d4a 272 }
el17sm 46:f09711580d4a 273
el17sm 46:f09711580d4a 274 void update_definite_doorways()
el17sm 46:f09711580d4a 275 {
el17sm 49:3f83ed62d123 276 update_definite_doorways_up();
el17sm 49:3f83ed62d123 277 update_definite_doorways_right();
el17sm 49:3f83ed62d123 278 update_definite_doorways_down();
el17sm 49:3f83ed62d123 279 update_definite_doorways_left();
el17sm 49:3f83ed62d123 280 }
el17sm 49:3f83ed62d123 281
el17sm 49:3f83ed62d123 282 void update_definite_doorways_up()
el17sm 49:3f83ed62d123 283 {
el17sm 49:3f83ed62d123 284 if (room_y == 1) { // if room to be generated is on the border, then doorway cannot exist
el17sm 46:f09711580d4a 285 cannot[0] = true;
el17sm 46:f09711580d4a 286 have_to[0] = false;
el17sm 50:2c5cb92a5361 287 } else if (valid_rooms[room_y - 1][room_x]){ // if room to be generated has an existing room above it
el17sm 50:2c5cb92a5361 288 if (rooms[room_y - 1][room_x]->get_doorway(2)){ // if room to be generated has an existing doorway, then doorway must exist
el17sm 46:f09711580d4a 289 have_to[0] = true;
el17sm 46:f09711580d4a 290 cannot[0] = false;
el17sm 50:2c5cb92a5361 291 } else { // if room to be generated does not have an existing doorway, then doorway must not exist
el17sm 46:f09711580d4a 292 have_to[0] = false;
el17sm 46:f09711580d4a 293 cannot[0] = true;
el17sm 46:f09711580d4a 294 }
el17sm 50:2c5cb92a5361 295 } else { // else the room does not have any definite doorways set on it's north
el17sm 46:f09711580d4a 296 have_to[0] = false;
el17sm 46:f09711580d4a 297 cannot[0] = false;
el17sm 46:f09711580d4a 298 }
el17sm 49:3f83ed62d123 299 }
el17sm 49:3f83ed62d123 300 void update_definite_doorways_right()
el17sm 49:3f83ed62d123 301 {
el17sm 50:2c5cb92a5361 302 if (room_x == 10) { // if room to be generated is on the border, then doorway cannot exist
el17sm 46:f09711580d4a 303 cannot[1] = true;
el17sm 46:f09711580d4a 304 have_to[1] = false;
el17sm 50:2c5cb92a5361 305 } else if (valid_rooms[room_y][room_x + 1]){ // if room to be generated has an existing room on it's right
el17sm 50:2c5cb92a5361 306 if (rooms[room_y][room_x + 1]->get_doorway(3)){ // if room to be generated has an existing doorway, then doorway must exist
el17sm 46:f09711580d4a 307 have_to[1] = true;
el17sm 46:f09711580d4a 308 cannot[1] = false;
el17sm 50:2c5cb92a5361 309 } else { // if room to be generated does not have an existing doorway, then doorway must not exist
el17sm 46:f09711580d4a 310 have_to[1] = false;
el17sm 46:f09711580d4a 311 cannot[1] = true;
el17sm 46:f09711580d4a 312 }
el17sm 50:2c5cb92a5361 313 } else { // else the room does not have any definite doorways set on it's right
el17sm 46:f09711580d4a 314 have_to[1] = false;
el17sm 46:f09711580d4a 315 cannot[1] = false;
el17sm 46:f09711580d4a 316 }
el17sm 49:3f83ed62d123 317 }
el17sm 49:3f83ed62d123 318
el17sm 49:3f83ed62d123 319 void update_definite_doorways_down()
el17sm 49:3f83ed62d123 320 {
el17sm 50:2c5cb92a5361 321 if (room_y == 10) { // if room to be generated is on the border, then doorway cannot exist
el17sm 46:f09711580d4a 322 cannot[2] = true;
el17sm 46:f09711580d4a 323 have_to[2] = false;
el17sm 50:2c5cb92a5361 324 } else if (valid_rooms[room_y + 1][room_x]){ // if room to be generated has an existing room below it
el17sm 50:2c5cb92a5361 325 if (rooms[room_y + 1][room_x]->get_doorway(0)){ // if room to be generated has an existing doorway, then doorway must exist
el17sm 46:f09711580d4a 326 have_to[2] = true;
el17sm 46:f09711580d4a 327 cannot[2] = false;
el17sm 50:2c5cb92a5361 328 } else { // if room to be generated does not have an existing doorway, then doorway must not exist
el17sm 46:f09711580d4a 329 have_to[2] = false;
el17sm 46:f09711580d4a 330 cannot[2] = true;
el17sm 46:f09711580d4a 331 }
el17sm 50:2c5cb92a5361 332 } else { // else the room does not have any definite doorways set on it's south
el17sm 46:f09711580d4a 333 have_to[2] = false;
el17sm 46:f09711580d4a 334 cannot[2] = false;
el17sm 46:f09711580d4a 335 }
el17sm 49:3f83ed62d123 336 }
el17sm 49:3f83ed62d123 337
el17sm 49:3f83ed62d123 338 void update_definite_doorways_left()
el17sm 49:3f83ed62d123 339 {
el17sm 50:2c5cb92a5361 340 if (room_x == 1) { // if room to be generated is on the border, then doorway cannot exist
el17sm 46:f09711580d4a 341 cannot[3] = true;
el17sm 46:f09711580d4a 342 have_to[3] = false;
el17sm 50:2c5cb92a5361 343 } else if (valid_rooms[room_y][room_x - 1]){ // if room to be generated has an existing room on it's left
el17sm 50:2c5cb92a5361 344 if (rooms[room_y][room_x - 1]->get_doorway(1)){ // if room to be generated has an existing doorway, then doorway must exist
el17sm 46:f09711580d4a 345 have_to[3] = true;
el17sm 46:f09711580d4a 346 cannot[3] = false;
el17sm 50:2c5cb92a5361 347 } else { // if room to be generated does not have an existing doorway, then doorway must not exist
el17sm 46:f09711580d4a 348 have_to[3] = false;
el17sm 46:f09711580d4a 349 cannot[3] = true;
el17sm 46:f09711580d4a 350 }
el17sm 50:2c5cb92a5361 351 } else { // else the room does not have any definite doorways set on it's left
el17sm 46:f09711580d4a 352 have_to[3] = false;
el17sm 46:f09711580d4a 353 cannot[3] = false;
el17sm 46:f09711580d4a 354 }
el17sm 48:f7d9ae3e554d 355 }