12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "Terrain.h"
- Terrain::Terrain(SDL_Surface* img)
- :Affichable(img)
- {
- SDL_Surface *tmpImg, *model;
- m_rect.w = m_rect.h = LG_CHUNK;
- for (int x(0); x<NB_X_CHUNK; x++)
- for (int y(0); y<NB_Y_CHUNK; y++)
- {
- // Création de la surface du chunk
- tmpImg = SDL_CreateRGBSurface(SDL_HWSURFACE, LG_CHUNK, LG_CHUNK, 32, 0, 0, 0, 0);
- m_rect.x = x * LG_CHUNK;
- m_rect.y = y * LG_CHUNK;
- SDL_BlitSurface(img, &m_rect, tmpImg, 0);
- // Optimisation surface
- model = tmpImg;
- tmpImg = SDL_DisplayFormat(model);
- SDL_FreeSurface(model);
- // Création du chunk
- m_chunk[NB_Y_CHUNK-y-1][x] = new Chunk(tmpImg, x, NB_Y_CHUNK-y-1);
- }
- }
- Terrain::~Terrain()
- {
- for (int x(0); x<NB_X_CHUNK; x++)
- for (int y(0); y<NB_Y_CHUNK; y++)
- delete m_chunk[y][x];
- }
- void Terrain::afficher(const Vec &lookAt, SDL_Surface* screen) const
- {
- ///Affichage optimisé
- for (int x(0); x<NB_X_CHUNK; x++)
- for (int y(0); y<NB_Y_CHUNK; y++)
- m_chunk[y][x]->afficher(lookAt, screen);
- }
|