Advertisement
Guest User

Untitled

a guest
Nov 17th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. void Map::Draw(int idmap)
  2. {
  3.     int camx, camy;
  4.     Camera::Get().GetPos(camx, camy);
  5.     camx -= GameConfig::Get().MapViewSizeW / 2;
  6.     camy -= GameConfig::Get().MapViewSizeH / 2;
  7.  
  8.     const int tilesize = GameConfig::Get().TileSize;
  9.  
  10. // рисуем только в видимой области экрана
  11.     for ( int x = 0; x < GameConfig::Get().MapViewSizeW; x++ )
  12.     {
  13.         for ( int y = 0; y < GameConfig::Get().MapViewSizeH; y++ )
  14.         {
  15.             int tx = x + camx;
  16.             int ty = y + camy;
  17.             if ( tx >= 0 && ty >= 0 )
  18.                 DrawBlock(idmap, tx, ty, x*tilesize, y*tilesize);
  19.         }
  20.     }
  21. }
  22.  
  23. void Map::DrawBlock(int idmap, int x, int y, int tx, int ty)
  24. {
  25. // рисуем блок текущей карты
  26.     m_blocks[x][y].Draw(tx, ty, (float)idmap / GameConfig::Get().MapZ);
  27.  
  28. // если это специальный пустой блок, то рисуем под ним блок с нижней карты и так до самого дна
  29.     if ( m_blocks[x][y].IsFree() )
  30.     {
  31.         if ( idmap < (World::Get().GetMaps().size() - 1) )
  32.             World::Get().GetMaps()[idmap + 1].DrawBlock(idmap + 1, x, y, tx, ty);      
  33.     }  
  34. }
  35.  
  36. // функция рисования спрайта
  37. void Sprite::Draw(float x, float y, float z)
  38.     {
  39.         Render::Get().GetDefQuad().SetDepth(z);
  40.         m_tex.Bind();
  41.  
  42.         Render::Get().GetDefQuad().SetSize(glm::vec2((float)m_tex.GetWidth(), (float)m_tex.GetHeight()));
  43.         Render::Get().GetDefQuad().SetTexRect(glm::vec4(m_rect.x, m_rect.y,
  44.             m_rect.z + m_rect.x - 1, m_rect.w + m_rect.y - 1));
  45.  
  46.         Render::Get().GetDefQuad().SetSize(m_size);
  47.         Render::Get().GetDefQuad().SetFlip(m_flip.x, m_flip.y);
  48.         Render::Get().GetDefQuad().Draw(glm::vec2(x, y));
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement