/* [CONSTRUCTOR] Construction d'un xMarioGrass =========================================================*/ xMarioGrass::xMarioGrass(xManager *m, SDL_Rect rect){ _manager = m; // Note: le rect correspond a un nombre de bloc // On convertit le tout en blocs reels int xMin = rect.x; int xMax = rect.w + rect.x - 1; int yMin = rect.y; int yMax = rect.h + rect.y - 1; /* (1) On charge la texture */ _spritesheet = IMG_LoadTexture(_manager->renderer(), "src/ground.png"); int index = 0; /* (2) On cree les plans (layers) */ for( int y = yMin ; y <= yMax ; y++ ){ for( int x = xMin ; x <= xMax ; x++ ){ // On cree une copie du spritesheet this->add( new xSprite(_manager, _spritesheet) ); // TOP-LEFT if( x == xMin && y == yMin ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){137, 99, 16, 16} ); } // TOP RIGHT else if( x == xMax && y == yMin ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){171, 99, 16, 16} ); } // BOTTOM LEFT else if( x == xMin && y == yMax ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){137, 133, 16, 16} ); } // BOTTOM RIGHT else if( x == xMax && y == yMax ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){171, 133, 16, 16} ); } // LEFT else if( x == xMin ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){137, 116, 16, 16} ); } // RIGHT else if( x == xMax ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){171, 116, 16, 16} ); } // TOP else if( y == yMin ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){154, 99, 16, 16} ); } // BOTTOM else if( y == yMax ){ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){137, 184, 16, 16} ); } // INSIDE else{ this->get(index)->dimensions( (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}, (SDL_Rect){137, 167, 16, 16} ); } index++; } } }