Moortiii

Untitled

Dec 9th, 2018
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.56 KB | None | 0 0
  1. try {
  2.         room->doorLeft   = roomGrid.at(room->gridX + (dungeonWidth / 2)).at(room->gridY + (dungeonHeight / 2) - 1) != nullptr;
  3.         room->doorRight  = roomGrid.at(room->gridX + (dungeonWidth / 2)).at(room->gridY + (dungeonHeight / 2) + 1) != nullptr;
  4.         room->doorTop    =  roomGrid.at(room->gridX + (dungeonWidth / 2) - 1).at(room->gridY + (dungeonHeight / 2)) != nullptr;
  5.         room->doorBottom =  roomGrid.at(room->gridX + (dungeonWidth / 2) + 1).at(room->gridY + (dungeonHeight / 2)) != nullptr;
  6.     } catch(std::out_of_range const& e) {
  7.         LOG_F(WARNING, "Vector tried to go out of range: %s", e.what());
  8.     }
  9.  
  10. for(int row = 0; row < roomGrid.size(); row++) {
  11.         for(int column = 0; column < roomGrid[row].size(); column++) {
  12.             if(roomGrid[row][column] != nullptr) {
  13.                 auto room = roomGrid[row][column];
  14.                 auto playerRoom = dungeon->getCurrentRoom();
  15.  
  16.                 Room* neighborBot = nullptr;
  17.                 Room* neighborTop = nullptr;
  18.                 Room* neighborLeft = nullptr;
  19.                 Room* neighborRight = nullptr;
  20.  
  21.                 try {
  22.                     neighborBot   = roomGrid.at(row + 1).at(column);
  23.                     neighborTop   = roomGrid.at(row - 1).at(column);
  24.                     neighborLeft  = roomGrid.at(row).at(column - 1);
  25.                     neighborRight = roomGrid.at(row).at(column + 1);
  26.                 } catch(std::out_of_range const& e) {
  27.                     // This actually loops ALL the time so it's a bad idea to log it
  28.                     //LOG_F(INFO, "Tried to access room outside of range in minimap: %s", e.what());
  29.                 }
  30.  
  31.                 if(neighborBot != nullptr) {
  32.                     if(room->doorBottom && playerRoom == room && !neighborBot->explored)
  33.                         neighborBot->spotted = true;
  34.                 }
  35.  
  36.                 if(neighborTop != nullptr) {
  37.                     if(room->doorTop && playerRoom == room && !neighborTop->explored)
  38.                         neighborTop->spotted = true;
  39.                 }
  40.  
  41.                 if(neighborLeft != nullptr) {
  42.                     if(room->doorLeft && playerRoom == room && !neighborLeft->explored)
  43.                         neighborLeft->spotted = true;
  44.                 }
  45.  
  46.                 if(neighborRight != nullptr) {
  47.                     if(room->doorRight && playerRoom == room && !neighborRight->explored)
  48.                         neighborRight->spotted = true;
  49.                 }
  50.  
  51.                 // TODO: Find a way to get the dungeon dimensions directly
  52.                 // Dungeonheight and width / 2 = 5. This centers the map around the starting room
  53.                 int renderColumn = column - 5;
  54.                 int renderRow    = row - 5;
  55.  
  56.                 SDL_Rect rect = getRect(renderColumn, renderRow);
  57.  
  58.                 // SPOTTED ROOMS
  59.                 if(room->spotted) {
  60.                     SDL_SetRenderDrawColor(getRenderer(), 100, 100, 100, 255);
  61.                     SDL_RenderFillRect(getRenderer(), &rect);
  62.                 }
  63.  
  64.                 // EXPLORED ROOMS
  65.                 if(room->explored) {
  66.                     SDL_SetRenderDrawColor(getRenderer(), 255, 255, 255, 255);
  67.                     SDL_RenderFillRect(getRenderer(), &rect);
  68.                 }
  69.  
  70.                 // STARTING ROOM
  71.                 if(roomGrid[row][column]->gridY == 0 && roomGrid[row][column]->gridX == 0) {
  72.                     SDL_SetRenderDrawColor(getRenderer(), 168, 209, 138, 255);
  73.                     SDL_RenderFillRect(getRenderer(), &rect);
  74.                 }
  75.  
  76.                 // CURRENT ROOM
  77.                 if(room == playerRoom) {
  78.                     SDL_SetRenderDrawColor(getRenderer(), 83, 150, 153, 255);
  79.                     SDL_RenderFillRect(getRenderer(), &rect);
  80.                 }
  81.  
  82.                 // BOSS ROOM
  83.                 if(room->type == BOSS && room->spotted){
  84.                     SDL_SetRenderDrawColor(getRenderer(), 199, 0, 57, 255);
  85.                     SDL_RenderFillRect(getRenderer(), &rect);
  86.                 }
  87.  
  88.                 if(room->type == TREASURE && room->spotted){
  89.                     SDL_SetRenderDrawColor(getRenderer(), 255, 195, 1, 255);
  90.                     SDL_RenderFillRect(getRenderer(), &rect);
  91.                 }
  92.  
  93.                 if(debug) {
  94.                     LOG_F(INFO, "Debug Mode enabled for minimap. Displaying entire map");
  95.                     SDL_SetRenderDrawColor(getRenderer(), 255, 100, 0, 255);
  96.                     SDL_RenderFillRect(getRenderer(), &rect);
  97.                 }
  98.             }
  99.         }
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment