Terrain.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "Terrain.h"
  2. Terrain::Terrain(SDL_Surface* img)
  3. :Affichable(img)
  4. {
  5. SDL_Surface *tmpImg, *model;
  6. m_rect.w = m_rect.h = LG_CHUNK;
  7. for (int x(0); x<NB_X_CHUNK; x++)
  8. for (int y(0); y<NB_Y_CHUNK; y++)
  9. {
  10. // Création de la surface du chunk
  11. tmpImg = SDL_CreateRGBSurface(SDL_HWSURFACE, LG_CHUNK, LG_CHUNK, 32, 0, 0, 0, 0);
  12. m_rect.x = x * LG_CHUNK;
  13. m_rect.y = y * LG_CHUNK;
  14. SDL_BlitSurface(img, &m_rect, tmpImg, 0);
  15. // Optimisation surface
  16. model = tmpImg;
  17. tmpImg = SDL_DisplayFormat(model);
  18. SDL_FreeSurface(model);
  19. // Création du chunk
  20. m_chunk[NB_Y_CHUNK-y-1][x] = new Chunk(tmpImg, x, NB_Y_CHUNK-y-1);
  21. }
  22. }
  23. Terrain::~Terrain()
  24. {
  25. for (int x(0); x<NB_X_CHUNK; x++)
  26. for (int y(0); y<NB_Y_CHUNK; y++)
  27. delete m_chunk[y][x];
  28. }
  29. void Terrain::afficher(const Vec &lookAt, SDL_Surface* screen) const
  30. {
  31. ///Affichage optimisé
  32. for (int x(0); x<NB_X_CHUNK; x++)
  33. for (int y(0); y<NB_Y_CHUNK; y++)
  34. m_chunk[y][x]->afficher(lookAt, screen);
  35. }