void CMap::Draw() { // If we don't need to update the screen, we just quit the function if(!m_bDrawScreen) return; // If we drawing, let's reset the flag so we don't draw again, unless needed m_bDrawScreen = false; SMALL_RECT drawRect = {0, 0, kMapWidth - 1, kMapHeight - 1}; // This is the drawing rectangle COORD bufferSize = {kMapWidth , kMapHeight}; // This stores the size of our buffer COORD zeroZero = {0, 0}; // This tells us the upper left corner to draw from DWORD dwResult = 0; // This stores the result of the draw operation char szCursor[2] = ""; // This string stores the cursor tile character // Get an OUTPUT handle to our screen. HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); // Here we go through our normal map tile list and add them to our drawing screen buffer for(int i = 0; i < (int)m_vTiles.size(); i++) { // Here we get the CHAR_INFO of the current tile in our list m_screenBuffer[i] = m_vTiles[i].GetChar(); } // Go through all of the items and draw their character/attribute to our map for(int i = 0; i < (int)m_vItems.size(); i++) { // Grab the position of the item and insert it into the map's screen buffer COORD index = m_vItems[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vItems[i].GetChar(), m_screenBuffer[slot]); } // Go through all of the npcs and draw their character/attribute to our map for(int i = 0; i < (int)m_vNpcs.size(); i++) { // Grab the position of the npc and insert it into the map's screen buffer COORD index = m_vNpcs[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vNpcs[i].GetChar(), m_screenBuffer[slot]); } // Go through all of the monsters and draw their character/attribute to our map for(int i = 0; i < (int)m_vMonsters.size(); i++) { // Grab the position of the monster and insert it into the map's screen buffer COORD index = m_vMonsters[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vMonsters[i].GetChar(), m_screenBuffer[slot]); } // Here we actually draw all the map and editor tiles to our screen WriteConsoleOutput(hOutput, m_screenBuffer, bufferSize, zeroZero, &drawRect); // After the map is drawn, let's draw the player over top of the map g_Player.Draw(); }
void CMap::Draw() { // If we don't need to update the screen, we just quit the function if(!m_bDrawScreen) return; // If we drawing, let's reset the flag so we don't draw again, unless needed m_bDrawScreen = false; SMALL_RECT drawRect = {0, 0, kMapWidth - 1, kMapHeight - 1}; // This is the drawing rectangle COORD bufferSize = {kMapWidth , kMapHeight}; // This stores the size of our buffer COORD zeroZero = {0, 0}; // This tells us the upper left corner to draw from DWORD dwResult = 0; // This stores the result of the draw operation char szCursor[2] = ""; // This string stores the cursor tile character // Get an OUTPUT handle to our screen. HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); // Here we go through our normal map tile list and add them to our drawing screen buffer for(int i = 0; i < (int)m_vTiles.size(); i++) { // Here we get the CHAR_INFO of the current tile in our list m_screenBuffer[i] = m_vTiles[i].GetChar(); } // Go through all of the items and draw their character/attribute to our map for(int i = 0; i < (int)m_vItems.size(); i++) { // Grab the position of the item and insert it into the map's screen buffer COORD index = m_vItems[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vItems[i].GetChar(), m_screenBuffer[slot]); } // Go through all of the npcs and draw their character/attribute to our map for(int i = 0; i < (int)m_vNpcs.size(); i++) { // Grab the position of the npc and insert it into the map's screen buffer COORD index = m_vNpcs[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vNpcs[i].GetChar(), m_screenBuffer[slot]); } // Go through all of the monsters and draw their character/attribute to our map for(int i = 0; i < (int)m_vMonsters.size(); i++) { // Grab the position of the monster and insert it into the map's screen buffer COORD index = m_vMonsters[i].GetIndex(); int slot = index.X + index.Y * kMapWidth; // Change the background color to the map's m_screenBuffer[slot] = AddNewBackground(m_vMonsters[i].GetChar(), m_screenBuffer[slot]); } // Here we actually draw all the map and editor tiles to our screen WriteConsoleOutput(hOutput, m_screenBuffer, bufferSize, zeroZero, &drawRect); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Since we have a party option now, instead of just drawing the player we need // to go through all of the party and draw each player. g_Player.UpdateParty(); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Check if we should show the stats bar or not if(m_bShowStats) { char szStats[80] = {0}; // Here we just fill in a string with the players information sprintf(szStats, "Hp: %d Lvl: %d Exp: %d $: %d ", g_Player.GetHealth(), g_Player.GetLevel(), g_Player.GetExperience(), g_Player.GetGold()); // Here we draw a box surrounding the stats with a padding of 4 for // height and width, which we then draw the string in the middle of that box. g_Menu.DrawBox((int)strlen(szStats) + 4, 4, kMapStatsX, kMapStatsY); g_Menu.DrawString(szStats, (int)strlen(szStats), kMapStatsX + 2, kMapStatsY + 2); } }