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

107 lines
2.5 KiB
C++

/* [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");
// Evite de la dupliquer, uniquement des pointeurs
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) );
// On definit le tyoe
_sprites[index]->setType("Grass");
// TOP-LEFT
if( x == xMin && y == yMin ){
_sprites[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 ){
_sprites[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 ){
_sprites[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 ){
_sprites[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 ){
_sprites[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 ){
_sprites[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 ){
_sprites[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 ){
_sprites[index]->dimensions(
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE},
(SDL_Rect){137, 184, 16, 16}
);
}
// INSIDE
else{
_sprites[index]->dimensions(
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE},
(SDL_Rect){137, 167, 16, 16}
);
}
index++;
}
}
}