Guest User

Untitled

a guest
Dec 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. /* Texture */
  2.  
  3. sf::Sprite Terrain::GetTexture(int terrainIndex)
  4. {
  5.     sf::Vector2i *tempSize = new sf::Vector2i(this->GetSize());
  6.  
  7.     int *nx = new int(1024 / tempSize->x);
  8.     int *ny = new int(1024 / tempSize->y);
  9.  
  10.     sf::IntRect *tempRect = new sf::IntRect
  11.         (
  12.             (terrainIndex % *nx) * tempSize->x,
  13.             ((terrainIndex/ *ny)) * tempSize->y, tempSize->x, tempSize->y
  14.         );
  15.    
  16.     this->_sprite.setTextureRect(sf::IntRect(*tempRect));  
  17.  
  18.     delete nx;
  19.     delete ny;
  20.     delete tempSize;
  21.     delete tempRect;
  22.  
  23.     return this->_sprite;
  24.  
  25. }
  26.  
  27. /* World */
  28.  
  29. void World::Draw(class Terrain *terrain)
  30. {
  31.     sf::Vector2i *tempSize = new sf::Vector2i(terrain->GetSize());
  32.  
  33.     int *y = new int;
  34.     int *x = new int;
  35.     for (*y = 0; *y < this->_mapSize.y; (*y)++)
  36.     {
  37.         for (*x = 0; *x < this->_mapSize.x; (*x)++)
  38.         {  
  39.             terrain->SetPostion({*x * tempSize->x, *y * tempSize->y});
  40.             Application::Window->draw(terrain->GetTexture(this->_map[*x][*y]));    
  41.         }
  42.     }
  43.     delete x;
  44.     delete y;
  45.     delete tempSize;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment