#include #include #include #include #include "include/image.h" #include "include/main.h" #include "include/level_struct.h" int LoadLevel(char *file, struct level *lvl, SDL_Surface *screen, SDL_Rect *dest) { SDL_Rect rect; SDL_Rect tmp_rect; int tmp; int div_h, div_l; int i; lvl->map = SDL_LoadBMP (file); if (lvl->map == NULL) { printf("Impossible de charger %s: %s\n", file, SDL_GetError ()); return 1; } rect.x = 0; rect.y = 0; rect.w = lvl->map->w; rect.h = lvl->map->h; printf("%dx%d\n", rect.w, rect.h); if(dest->w < rect.w) { tmp = (rect.w / dest->w); div_l = tmp; if((tmp * dest->h) < rect.w) div_l++; printf("dist->w(%d) rect.w(%d) largeur(%d) div_l(%d)\n",dest->w, rect.w, tmp, div_l); tmp_rect.x = 0; tmp_rect.y = 0; for(i = 0; i < div_l; i++) { lvl->sdiv_l[i] = malloc(sizeof(SDL_Surface)); tmp_rect.w = dest->w; tmp_rect.h = dest->h; printf("x(%d) y(%d) w(%d) h(%d)\n", tmp_rect.x, tmp_rect.y, tmp_rect.w, tmp_rect.h); SDL_BlitSurface(lvl->map, &tmp_rect, lvl->sdiv_l[i], NULL); tmp_rect.x += dest->w; } lvl->div_l = div_l; } if(dest->h < rect.h) { tmp = rect.h % dest->h; div_h = tmp; if((tmp * dest->h) < rect.w) div_h++; printf("div_h : %d//\n", div_h); } return 0; } void FreeLevel(struct level *lvl) { int i; for(i = 0; i < lvl->div_l; i++) { free(lvl->sdiv_l[i]); } }