try {
room->doorLeft = roomGrid.at(room->gridX + (dungeonWidth / 2)).at(room->gridY + (dungeonHeight / 2) - 1) != nullptr;
room->doorRight = roomGrid.at(room->gridX + (dungeonWidth / 2)).at(room->gridY + (dungeonHeight / 2) + 1) != nullptr;
room->doorTop = roomGrid.at(room->gridX + (dungeonWidth / 2) - 1).at(room->gridY + (dungeonHeight / 2)) != nullptr;
room->doorBottom = roomGrid.at(room->gridX + (dungeonWidth / 2) + 1).at(room->gridY + (dungeonHeight / 2)) != nullptr;
} catch(std::out_of_range const& e) {
LOG_F(WARNING, "Vector tried to go out of range: %s", e.what());
}
for(int row = 0; row < roomGrid.size(); row++) {
for(int column = 0; column < roomGrid[row].size(); column++) {
if(roomGrid[row][column] != nullptr) {
auto room = roomGrid[row][column];
auto playerRoom = dungeon->getCurrentRoom();
Room* neighborBot = nullptr;
Room* neighborTop = nullptr;
Room* neighborLeft = nullptr;
Room* neighborRight = nullptr;
try {
neighborBot = roomGrid.at(row + 1).at(column);
neighborTop = roomGrid.at(row - 1).at(column);
neighborLeft = roomGrid.at(row).at(column - 1);
neighborRight = roomGrid.at(row).at(column + 1);
} catch(std::out_of_range const& e) {
// This actually loops ALL the time so it's a bad idea to log it
//LOG_F(INFO, "Tried to access room outside of range in minimap: %s", e.what());
}
if(neighborBot != nullptr) {
if(room->doorBottom && playerRoom == room && !neighborBot->explored)
neighborBot->spotted = true;
}
if(neighborTop != nullptr) {
if(room->doorTop && playerRoom == room && !neighborTop->explored)
neighborTop->spotted = true;
}
if(neighborLeft != nullptr) {
if(room->doorLeft && playerRoom == room && !neighborLeft->explored)
neighborLeft->spotted = true;
}
if(neighborRight != nullptr) {
if(room->doorRight && playerRoom == room && !neighborRight->explored)
neighborRight->spotted = true;
}
// TODO: Find a way to get the dungeon dimensions directly
// Dungeonheight and width / 2 = 5. This centers the map around the starting room
int renderColumn = column - 5;
int renderRow = row - 5;
SDL_Rect rect = getRect(renderColumn, renderRow);
// SPOTTED ROOMS
if(room->spotted) {
SDL_SetRenderDrawColor(getRenderer(), 100, 100, 100, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
// EXPLORED ROOMS
if(room->explored) {
SDL_SetRenderDrawColor(getRenderer(), 255, 255, 255, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
// STARTING ROOM
if(roomGrid[row][column]->gridY == 0 && roomGrid[row][column]->gridX == 0) {
SDL_SetRenderDrawColor(getRenderer(), 168, 209, 138, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
// CURRENT ROOM
if(room == playerRoom) {
SDL_SetRenderDrawColor(getRenderer(), 83, 150, 153, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
// BOSS ROOM
if(room->type == BOSS && room->spotted){
SDL_SetRenderDrawColor(getRenderer(), 199, 0, 57, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
if(room->type == TREASURE && room->spotted){
SDL_SetRenderDrawColor(getRenderer(), 255, 195, 1, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
if(debug) {
LOG_F(INFO, "Debug Mode enabled for minimap. Displaying entire map");
SDL_SetRenderDrawColor(getRenderer(), 255, 100, 0, 255);
SDL_RenderFillRect(getRenderer(), &rect);
}
}
}
}
Comments