Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Map::Draw(Graphics & gfx,Vei2 viewport)
- {
- //m_mapRect is rect for map on the actual game screen size and position
- //viewport is a cordinates of a viewport in worldmap 50000x50000 pixels
- //m_tiles is a vector<tiles> 1000x1000 tiles by 50x50 pixels
- //Vei2 is typedef _Vec2<int> Vei2
- int width = std::ceil(((float)m_mapRect.GetWidth() / 50));//how many tile in width
- int height = std::ceil(((float)m_mapRect.GetHeight() / 50));// how many tile in height
- Vei2 pos = viewport - Vei2(m_mapRect.GetWidth() / 2, m_mapRect.GetHeight() / 2); // position of viewport
- int startx = pos.x / 50;
- int starty = pos.y / 50;
- int at = startx * starty;// tile at viewport(first tile cordinates )
- int xcord = startx * 50 - pos.x;
- int ycord = starty * 50 - pos.y;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- // need cordinates where should i start draw tiles
- m_tiles[at * y + x].Draw((m_mapRect.left- xcord) + (x * 50),(m_mapRect.top-ycord)+ (y * 50),gfx);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement