Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. void Map::Draw(Graphics & gfx,Vei2 viewport)
  2. {
  3.     //m_mapRect is rect for map on the actual game screen size and position
  4.     //viewport is a cordinates of a viewport in worldmap 50000x50000 pixels
  5.     //m_tiles is a vector<tiles> 1000x1000 tiles by 50x50 pixels
  6.     //Vei2 is typedef _Vec2<int> Vei2
  7.     int width = std::ceil(((float)m_mapRect.GetWidth() / 50));//how many tile in width
  8.     int height = std::ceil(((float)m_mapRect.GetHeight() / 50));// how many tile in height
  9.     Vei2 pos = viewport - Vei2(m_mapRect.GetWidth() / 2, m_mapRect.GetHeight() / 2); // position of viewport
  10.     int startx = pos.x / 50;
  11.     int starty = pos.y / 50;
  12.     int at = startx * starty;// tile at viewport(first tile cordinates )
  13.     int xcord = startx * 50 - pos.x;
  14.     int ycord = starty * 50 - pos.y;
  15.     for (int y = 0; y < height; y++) {
  16.         for (int x = 0; x < width; x++) {
  17.             // need cordinates where should i start draw tiles
  18.             m_tiles[at * y + x].Draw((m_mapRect.left- xcord) + (x * 50),(m_mapRect.top-ycord)+ (y * 50),gfx);
  19.         }
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement