lab.cpp/SDL#4/xMario/xMarioGrass.cpp

104 lines
2.4 KiB
C++

/* [CONSTRUCTOR] Construction d'un xSMarioGrass
=========================================================*/
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/mario_ground.jpg");
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){1, 0, 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){35, 0, 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){1, 34, 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){35, 34, 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){1, 17, 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){35, 17, 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){18, 0, 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){18, 34, 16, 16}
);
}
// INSIDE
else{
this->get(index)->dimensions(
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE},
(SDL_Rect){18, 17, 16, 16}
);
}
index++;
}
}
}