diff --git a/images/01.png b/1/01.png similarity index 100% rename from images/01.png rename to 1/01.png diff --git a/images/afk2.png b/1/afk2.png similarity index 100% rename from images/afk2.png rename to 1/afk2.png diff --git a/images/afk3.png b/1/afk3.png similarity index 100% rename from images/afk3.png rename to 1/afk3.png diff --git a/images/afk4.png b/1/afk4.png similarity index 100% rename from images/afk4.png rename to 1/afk4.png diff --git a/images/afk5.png b/1/afk5.png similarity index 100% rename from images/afk5.png rename to 1/afk5.png diff --git a/images/afkleft2.png b/1/afkleft2.png similarity index 100% rename from images/afkleft2.png rename to 1/afkleft2.png diff --git a/images/afkleft3.png b/1/afkleft3.png similarity index 100% rename from images/afkleft3.png rename to 1/afkleft3.png diff --git a/images/afkleft4.png b/1/afkleft4.png similarity index 100% rename from images/afkleft4.png rename to 1/afkleft4.png diff --git a/images/afkleft5.png b/1/afkleft5.png similarity index 100% rename from images/afkleft5.png rename to 1/afkleft5.png diff --git a/images/bg.png b/1/bg.png similarity index 100% rename from images/bg.png rename to 1/bg.png diff --git a/1/dot.png b/1/dot.png new file mode 100755 index 0000000..e9fc942 Binary files /dev/null and b/1/dot.png differ diff --git a/images/ezgif.com-resize.png b/1/ezgif.com-resize.png similarity index 100% rename from images/ezgif.com-resize.png rename to 1/ezgif.com-resize.png diff --git a/images/jl1.png b/1/jl1.png similarity index 100% rename from images/jl1.png rename to 1/jl1.png diff --git a/images/jl10.png b/1/jl10.png similarity index 100% rename from images/jl10.png rename to 1/jl10.png diff --git a/images/jl11.png b/1/jl11.png similarity index 100% rename from images/jl11.png rename to 1/jl11.png diff --git a/images/jl12.png b/1/jl12.png similarity index 100% rename from images/jl12.png rename to 1/jl12.png diff --git a/images/jl13.png b/1/jl13.png similarity index 100% rename from images/jl13.png rename to 1/jl13.png diff --git a/images/jl14.png b/1/jl14.png similarity index 100% rename from images/jl14.png rename to 1/jl14.png diff --git a/images/jl2.png b/1/jl2.png similarity index 100% rename from images/jl2.png rename to 1/jl2.png diff --git a/images/jl3.png b/1/jl3.png similarity index 100% rename from images/jl3.png rename to 1/jl3.png diff --git a/images/jl4.png b/1/jl4.png similarity index 100% rename from images/jl4.png rename to 1/jl4.png diff --git a/images/jl5.png b/1/jl5.png similarity index 100% rename from images/jl5.png rename to 1/jl5.png diff --git a/images/jl6.png b/1/jl6.png similarity index 100% rename from images/jl6.png rename to 1/jl6.png diff --git a/images/jl7.png b/1/jl7.png similarity index 100% rename from images/jl7.png rename to 1/jl7.png diff --git a/images/jl8.png b/1/jl8.png similarity index 100% rename from images/jl8.png rename to 1/jl8.png diff --git a/images/jl9.png b/1/jl9.png similarity index 100% rename from images/jl9.png rename to 1/jl9.png diff --git a/images/jr1.png b/1/jr1.png similarity index 100% rename from images/jr1.png rename to 1/jr1.png diff --git a/images/jr10.png b/1/jr10.png similarity index 100% rename from images/jr10.png rename to 1/jr10.png diff --git a/images/jr11.png b/1/jr11.png similarity index 100% rename from images/jr11.png rename to 1/jr11.png diff --git a/images/jr12.png b/1/jr12.png similarity index 100% rename from images/jr12.png rename to 1/jr12.png diff --git a/images/jr13.png b/1/jr13.png similarity index 100% rename from images/jr13.png rename to 1/jr13.png diff --git a/images/jr14.png b/1/jr14.png similarity index 100% rename from images/jr14.png rename to 1/jr14.png diff --git a/images/jr2.png b/1/jr2.png similarity index 100% rename from images/jr2.png rename to 1/jr2.png diff --git a/images/jr3.png b/1/jr3.png similarity index 100% rename from images/jr3.png rename to 1/jr3.png diff --git a/images/jr4.png b/1/jr4.png similarity index 100% rename from images/jr4.png rename to 1/jr4.png diff --git a/images/jr5.png b/1/jr5.png similarity index 100% rename from images/jr5.png rename to 1/jr5.png diff --git a/images/jr6.png b/1/jr6.png similarity index 100% rename from images/jr6.png rename to 1/jr6.png diff --git a/images/jr7.png b/1/jr7.png similarity index 100% rename from images/jr7.png rename to 1/jr7.png diff --git a/images/jr8.png b/1/jr8.png similarity index 100% rename from images/jr8.png rename to 1/jr8.png diff --git a/images/jr9.png b/1/jr9.png similarity index 100% rename from images/jr9.png rename to 1/jr9.png diff --git a/images/option_menu_without_buttons.png b/1/option_menu_without_buttons.png similarity index 100% rename from images/option_menu_without_buttons.png rename to 1/option_menu_without_buttons.png diff --git a/images/pl1.png b/1/pl1.png similarity index 100% rename from images/pl1.png rename to 1/pl1.png diff --git a/images/pl2.png b/1/pl2.png similarity index 100% rename from images/pl2.png rename to 1/pl2.png diff --git a/images/pl3.png b/1/pl3.png similarity index 100% rename from images/pl3.png rename to 1/pl3.png diff --git a/images/pl4.png b/1/pl4.png similarity index 100% rename from images/pl4.png rename to 1/pl4.png diff --git a/images/pl5.png b/1/pl5.png similarity index 100% rename from images/pl5.png rename to 1/pl5.png diff --git a/images/pl6.png b/1/pl6.png similarity index 100% rename from images/pl6.png rename to 1/pl6.png diff --git a/images/pl7.png b/1/pl7.png similarity index 100% rename from images/pl7.png rename to 1/pl7.png diff --git a/images/pr1.png b/1/pr1.png similarity index 100% rename from images/pr1.png rename to 1/pr1.png diff --git a/images/pr2.png b/1/pr2.png similarity index 100% rename from images/pr2.png rename to 1/pr2.png diff --git a/images/pr3.png b/1/pr3.png similarity index 100% rename from images/pr3.png rename to 1/pr3.png diff --git a/images/pr4.png b/1/pr4.png similarity index 100% rename from images/pr4.png rename to 1/pr4.png diff --git a/images/pr5.png b/1/pr5.png similarity index 100% rename from images/pr5.png rename to 1/pr5.png diff --git a/images/pr6.png b/1/pr6.png similarity index 100% rename from images/pr6.png rename to 1/pr6.png diff --git a/images/pr7.png b/1/pr7.png similarity index 100% rename from images/pr7.png rename to 1/pr7.png diff --git a/images/small_bg.png b/1/small_bg.png similarity index 100% rename from images/small_bg.png rename to 1/small_bg.png diff --git a/images/small_game_development.png b/1/small_game_development.png similarity index 100% rename from images/small_game_development.png rename to 1/small_game_development.png diff --git a/images/stage1-01.png b/1/stage1-01.png similarity index 100% rename from images/stage1-01.png rename to 1/stage1-01.png diff --git a/images/stage1.bmp b/1/stage1.bmp similarity index 100% rename from images/stage1.bmp rename to 1/stage1.bmp diff --git a/AbrilFatface-Regular.ttf b/AbrilFatface-Regular.ttf new file mode 100755 index 0000000..a291711 Binary files /dev/null and b/AbrilFatface-Regular.ttf differ diff --git a/fonction.c b/fonction.c deleted file mode 100755 index f9a90f0..0000000 --- a/fonction.c +++ /dev/null @@ -1,603 +0,0 @@ -#include -#include "fonction.h" -#include "text.h" -#include -#include -#include - -void init_hero(hero* h,int choix) -{ - - h->heroright[0]= IMG_Load("images/pr2.png"); - h->heroleft[0]= IMG_Load("images/pl2.png"); - - h->heroright[1]= IMG_Load("images/pr3.png"); - h->heroleft[1]= IMG_Load("images/pl3.png"); - - h->heroright[2]= IMG_Load("images/pr4.png"); - h->heroleft[2]= IMG_Load("images/pl4.png"); - - h->heroright[3]= IMG_Load("images/pr5.png"); - h->heroleft[3]= IMG_Load("images/pl5.png"); - - h->heroright[4]= IMG_Load("images/pr6.png"); - h->heroleft[4]= IMG_Load("images/pl6.png"); - - h->heroright[5]= IMG_Load("images/pr7.png"); - h->heroleft[5]= IMG_Load("images/pl7.png"); - - - - - h->idleright[0]= IMG_Load("images/pr1.png"); - h->idleright[1]= IMG_Load("images/afk2.png"); - h->idleright[2]= IMG_Load("images/afk3.png"); - h->idleright[3]= IMG_Load("images/afk4.png"); - h->idleright[4]= IMG_Load("images/afk5.png"); - - h->idleleft[0]= IMG_Load("images/pl1.png"); - h->idleleft[1]= IMG_Load("images/afkleft2.png"); - h->idleleft[2]= IMG_Load("images/afkleft3.png"); - h->idleleft[3]= IMG_Load("images/afkleft4.png"); - h->idleleft[4]= IMG_Load("images/afkleft5.png"); - - - - h->jumpright[0]= IMG_Load("images/jr1.png"); - h->jumpright[1]= IMG_Load("images/jr2.png"); - h->jumpright[2]= IMG_Load("images/jr3.png"); - h->jumpright[3]= IMG_Load("images/jr4.png"); - h->jumpright[4]= IMG_Load("images/jr5.png"); - h->jumpright[5]= IMG_Load("images/jr6.png"); - h->jumpright[6]= IMG_Load("images/jr7.png"); - h->jumpright[7]= IMG_Load("images/jr8.png"); - h->jumpright[8]= IMG_Load("images/jr9.png"); - h->jumpright[9]= IMG_Load("images/jr10.png"); - - - - h->jumpleft[0]= IMG_Load("images/jl1.png"); - h->jumpleft[1]= IMG_Load("images/jl2.png"); - h->jumpleft[2]= IMG_Load("images/jl3.png"); - h->jumpleft[3]= IMG_Load("images/jl4.png"); - h->jumpleft[4]= IMG_Load("images/jl5.png"); - h->jumpleft[5]= IMG_Load("images/jl6.png"); - h->jumpleft[6]= IMG_Load("images/jl7.png"); - h->jumpleft[7]= IMG_Load("images/jl8.png"); - h->jumpleft[8]= IMG_Load("images/jl9.png"); - h->jumpleft[9]= IMG_Load("images/jl10.png"); - - - h->fallright[0]= IMG_Load("images/jr11.png"); - h->fallright[1]= IMG_Load("images/jr12.png"); - h->fallright[2]= IMG_Load("images/jr13.png"); - h->fallright[3]= IMG_Load("images/jr14.png"); - - - h->fallleft[0]= IMG_Load("images/jl11.png"); - h->fallleft[1]= IMG_Load("images/jl12.png"); - h->fallleft[2]= IMG_Load("images/jl13.png"); - h->fallleft[3]= IMG_Load("images/jl14.png"); - - - h->heroposition.x = 100; - h->heroposition.y = 600; - h->heroposition.w = 120; - h->heroposition.h = 80; - h->sens= 0; - h->frame= 0; - h->idle=0; - h->jump=0; - h->fall=0; - - - - h->heroisjumping = 0; - h->speedup = 0 ; - h->speeddown = 10 ; - h->directionjump = 1; - h->ground = 600 ; - h->gravity = 0; - h->herospeed=0; - - h->vitesse = 5; - h->acceleration = 0; -} -void blit_hero( hero* h,SDL_Surface *screen) -{ - if ( h->sens == 0 ) - { - SDL_BlitSurface(h->heroright[h->frame],NULL,screen,&h->heroposition); - } - else if (h->sens == 1) - { - SDL_BlitSurface(h->heroleft[h->frame],NULL,screen,&h->heroposition); - } - - - - else if(h->sens == -1) - { - SDL_BlitSurface(h->idleright[h->idle],NULL,screen,&h->heroposition); - } - else if(h->sens==-2) - { - SDL_BlitSurface(h->idleleft[h->idle],NULL,screen,&h->heroposition); - } - - - - else if(h->sens == 3) - { - SDL_BlitSurface(h->jumpright[h->jump],NULL,screen,&h->heroposition); - } - else if(h->sens == -3) - { - SDL_BlitSurface(h->jumpleft[h->jump],NULL,screen,&h->heroposition); - } - - - - else if(h->sens == 4) - { - SDL_BlitSurface(h->fallright[h->fall],NULL,screen,&h->heroposition); - } - else if(h->sens == -4) - { - SDL_BlitSurface(h->fallleft[h->fall],NULL,screen,&h->heroposition); - } - -} - - - -void animation (hero* h,int choix) -{ -h->frame++; -if(h->frame >=6) -{ -h->frame=1; -} -SDL_Delay(20); -} - - - -void idle(hero* h) -{ -h->idle++; -if(h->idle>=5) -{ -h->idle=0; -} -SDL_Delay(100); -} - - - - -void jumpanimation(hero* h) -{ - h->jump++; - if(h->jump>=10) - { - h->jump=0; - } - SDL_Delay(1); -} - - - -void fall(hero* h) -{ - h->fall++; - if(h->fall>=4) - { - h->fall=0; - } - SDL_Delay(200); -} - - - -void Free_hero(hero* h) -{ - int i; - int j; - int k; - int q; - for (i=0;i<6;i++) - { - SDL_FreeSurface(h->heroright[i]); - SDL_FreeSurface(h->heroleft[i]); - } - for (j=0;j<5;j++) - { - SDL_FreeSurface(h->idleright[j]); - SDL_FreeSurface(h->idleleft[j]); - } - for (k=0;k<4;k++) - { - SDL_FreeSurface(h->fallright[k]); - SDL_FreeSurface(h->fallleft[k]); - } - for (q=0;q<10;q++) - { - SDL_FreeSurface(h->jumpright[q]); - SDL_FreeSurface(h->jumpleft[q]); - } - -} - - - -void jump(hero* h) -{ - - if ( h->heroisjumping == 1 ) - { - if ( h->gravity == 0 ) - { - h->heroposition.y -= (h->heroposition.y/22); - SDL_Delay(h->speedup); - } - if( h->speedup <= 5) - { - h->speedup +=1; - } - - - if ( h->ground - h->heroposition.y >= 250 ) - { - h->gravity = 1; - } - if ( h->gravity == 1 ) - { - SDL_Delay(h->speeddown); - if ( h->speeddown >=1 ) - { - h->speeddown -= 1; - } - if ( h->heroposition.y >= h->ground ) - { - h->heroposition.y = h->ground; - restart_jump(h); - h->heroisjumping = 0; - } - if ( h->heroposition.y != h->ground ) - { - h->heroposition.y += (h->heroposition.y/22); - } - } - } -} -void restart_jump ( hero* h ) -{ - h->speedup = 0; - h->gravity = 0; - h->speeddown = 20; -} -void deplacer_perso(hero *p,Uint32 dt) -{ - int dx; - dx=((p->acceleration/2)*(dt*dt))+(p->vitesse*dt); - if((p->sens==1)&&(p->T[7].c!=1)) - { - p->heroposition.x-=(dx/10); - //p->heroposition.x--; - } - else if((p->sens==0)&&(p->T[3].c!=1)) - { - p->heroposition.x+=(dx/10); - //p->heroposition.x++; - } -} -int choix_hero() -{ - SDL_Event event; - int continuer=1; - while(continuer == 1) - { - - SDL_PollEvent(&event); - switch(event.type) - { - case SDL_QUIT: - continuer=0; - - break; - - case SDL_KEYDOWN: - { - switch(event.key.keysym.sym) - { - case SDLK_ESCAPE: - continuer=0; - break; - case SDLK_RIGHT : - { - return 1; - } - break; - case SDLK_LEFT : - { - return 2; - } - break; - } - break; - } - } - } -} -//background - -Mix_Music* initsound (char ch[]) -{ - return Mix_LoadMUS (ch); -} - - -void initBack(background *b,char ch[]) -{ - b->img = IMG_Load(ch); - if ( b->img == NULL) - { - return; - } - b->pos1.x=0; - b->pos1.y=0; - b->pos2.x=0; - b->pos2.y=0; - b->pos2.w=(5768); - b->pos2.h=(1050); - -} - -void initBack2(background *b,char ch[]) -{ - b->img = SDL_LoadBMP(ch); - if ( b->img == NULL) - { - return; - } - b->pos1.x=0; - b->pos1.y=0; - b->pos2.x=0; - b->pos2.y=0; - b->pos2.w=(5768); - b->pos2.h=(1050); - -} - - -void initBut(background *score,char ch[]) -{ - score->img = IMG_Load(ch); - if ( score->img == NULL) - { - return; - } - score->pos1.x=800; - score->pos1.y=10; - score->pos2.x=0; - score->pos2.y=0; - score->pos2.w=(5768); - score->pos2.h=(1050); - -} - - - -void scrolling (background * b, int direction , Uint32 dt , hero *p ) -{ - int dx; - dx=p->heroposition.x; - if (direction==1) - { - if(b->pos2.x>2000) - { - b->pos2.x=0; - } - else - b->pos2.x=dx; - } - else if (direction==2) - if (b->pos2.x<0) - { - - } - else - b->pos2.x=dx; - /*else if (direction==3) - if (b->pos2.y <-50) - { - - } - else - b->pos2.y=dx; - - else if (direction==4) - if (b->pos2.y> 150) - { - - } - else - b->pos2.y=dx;*/ -} - - - -void savescore(scoreinfo xs,char *ch) -{ - FILE* f; - f= fopen(ch, "a"); - if(f== NULL) - { - printf("error"); - } - - printf("Donner le nom de joueur: "); - scanf("%s",xs.playername); - printf("\n"); - fprintf(f, "%d %d %s\n", xs.score, (xs.temps/1000), xs.playername); - - fclose(f); - -} - - -void bestscore(char *ch,scoreinfo ts[],Text t2, SDL_Surface *screen) -{ - char xch[999]; - int n=0; - int i,j; - int max; - scoreinfo tampon; - FILE* f; - f= fopen(ch, "r"); - if(f== NULL) - { - printf("error"); - } - while( fscanf(f, "%d %d %s\n",&ts[n].score,&ts[n].temps,ts[n].playername)!= EOF ) - { - n++; - } - for (i=0; its[max].score) - { - max=j; - } - else if (ts[j].score==ts[max].score) - { - if (ts[j].tempsT[0].x=C->heroposition.x; - C->T[0].y=C->heroposition.y; - C->T[0].c=0; - - C->T[1].x=C->heroposition.x+ C->heroposition.w/2; - C->T[1].y=C->heroposition.y; - C->T[1].c=0; - - C->T[2].x=C->heroposition.x + C->heroposition.w; - C->T[2].y=C->heroposition.y; - C->T[2].c=0; - - C->T[3].x=C->heroposition.x+C->heroposition.w; - C->T[3].y=C->heroposition.y + C->heroposition.h /2; - C->T[3].c=0; - - C->T[4].x=C->heroposition.x+C->heroposition.w; - C->T[4].y=C->heroposition.y+C->heroposition.h; - C->T[4].c=0; - - C->T[5].x=C->heroposition.x + C->heroposition.w/2; - C->T[5].y=C->heroposition.y+ C->heroposition.h ; - C->T[5].c=0; - - C->T[6].x=C->heroposition.x; - C->T[6].y=C->heroposition.y+C->heroposition.h; - C->T[6].c=0; - - C->T[7].x=C->heroposition.x; - C->T[7].y=C->heroposition.y+C->heroposition.h/2; - C->T[7].c=0; - - -} - - -SDL_Color GetPixel(SDL_Surface *p , int x , int y) -{ - SDL_Color color; - Uint32 col=0; - - char * Pos = (char*)p->pixels; - Pos += (p->pitch * y); - Pos += (p->format->BytesPerPixel * x); - memcpy (&col ,Pos, p->format->BytesPerPixel ); - - SDL_GetRGB(col , p->format,&color.r , &color.g,&color.b ); - return color; - -} - -void collision (hero *C , background B ) -{ - SDL_Color color ,color2; - int i=0; - color.r=5; - color.g=5; - color.b=5; - tab(C); - while (i<8) - { - color2=GetPixel(B.img , C->T[i].x+B.pos2.x , C->T[i].y+B.pos2.y ); - if ((color.r>=color2.r)&&(color.g>=color2.g)&&(color.b>=color2.b) ) - { - C->T[i].c = 1; - } - i++; - } -} - - - - - - - - - - - - - - diff --git a/fonction.h b/fonction.h deleted file mode 100755 index 77fd420..0000000 --- a/fonction.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef fonction_H -#define fonction_H -#include -#include -#include -#include -#include "text.h" -#include "minimap.h" -#define SCREEN_W 1924 -#define SCREEN_H 720 - -typedef struct -{ - int x; - int y; - int c; -}point; - -struct hero -{ - SDL_Surface * heroright[6]; - SDL_Surface * heroleft[6]; - - SDL_Surface * idleright[5]; - SDL_Surface * idleleft[5]; - - SDL_Surface * jumpright[10]; - SDL_Surface * jumpleft[10]; - - SDL_Surface * fallright[4]; - SDL_Surface * fallleft[4]; - - SDL_Rect heroposition; - int sens; - int frame; - int idle; - int jump; - int fall; - int heroisjumping,gravity,speedup,speeddown,directionjump,ground,herospeed; - double vitesse,acceleration; - point T[8]; -}; -typedef struct hero hero; - - - -typedef struct -{ - SDL_Rect pos1; - SDL_Rect pos2; - SDL_Surface *img; -}background; - -Mix_Music* initsound (); - -typedef struct -{ - int score; - int temps; - char playername[20]; -}scoreinfo; - -void init_hero(hero* h,int choix); -void blit_hero( hero* h,SDL_Surface *screen); - -void animation (hero* h,int choix); -void idle(hero* h); -void fall(hero* h); -void jumpanimation(hero* h); - -void Free_hero(hero* h); - -void jump(hero* h); -void restart_jump ( hero* h ); - -void deplacer_perso(hero *p,Uint32 dt); -int choix_hero(); - - -void tab(hero *C); - -SDL_Color GetPixel(SDL_Surface *p , int x , int y); -void collision (hero *C , background B ); - - - - -void initBack( background *b,char ch[]); - -void initBack2(background *b,char ch[]); -void initBut (background *score,char ch[]); - -void scrolling (background * b, int direction , Uint32 dt , hero *p ); -void afficher(background b,SDL_Surface *screen); -void savescore(scoreinfo xs,char *ch); -void bestscore(char *ch,scoreinfo ts[],Text t2,SDL_Surface *screen); - -void liberer( background b); - - - - - -#endif diff --git a/images/back_button.png b/images/back_button.png new file mode 100755 index 0000000..5295321 Binary files /dev/null and b/images/back_button.png differ diff --git a/images/bg/1.png b/images/bg/1.png new file mode 100755 index 0000000..ae0847b Binary files /dev/null and b/images/bg/1.png differ diff --git a/images/bg/2.png b/images/bg/2.png new file mode 100755 index 0000000..551f4ef Binary files /dev/null and b/images/bg/2.png differ diff --git a/images/bg/3.png b/images/bg/3.png new file mode 100755 index 0000000..9425236 Binary files /dev/null and b/images/bg/3.png differ diff --git a/images/masque_stage1.bmp b/images/masque_stage1.bmp new file mode 100755 index 0000000..2d3d627 Binary files /dev/null and b/images/masque_stage1.bmp differ diff --git a/images/mini/1.png b/images/mini/1.png new file mode 100755 index 0000000..befbc7d Binary files /dev/null and b/images/mini/1.png differ diff --git a/images/mini/2.png b/images/mini/2.png new file mode 100755 index 0000000..30e2b98 Binary files /dev/null and b/images/mini/2.png differ diff --git a/images/mini/3.png b/images/mini/3.png new file mode 100755 index 0000000..55b4ea1 Binary files /dev/null and b/images/mini/3.png differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..9a994d1 --- /dev/null +++ b/main.c @@ -0,0 +1,135 @@ +#include +#include +#include +#include +#include "minimap.h" +#include + +int main(int argc,char *argv[]) + + +{ + TTF_Init(); + SDL_Init (SDL_INIT_VIDEO); + SDL_Event event ; + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY , SDL_DEFAULT_REPEAT_INTERVAL ); + int done = 0 , direction =0 ,i=0; + + + int startime=-1 ,time=0 , timeL = 169000 , j; + image mask ,bg[3]; + minimap M; + perso C; + SDL_Surface *screen; + Text T; + screen = SDL_SetVideoMode (SCREEN_W , SCREEN_H,32 , SDL_HWSURFACE |SDL_SRCALPHA|SDL_DOUBLEBUF); + + initText(&T,1180,20,125,0,0,50); + initMinimap (&M); + initback (&mask); + initAnime ( bg, "images/bg/",".png" , 3 , 0, 0,0,0, 5768,1080); + initC(&C.I); + while (done!=1) + { + + playAnime2 ( bg , screen , 3 , &i); + playAnime2 ( M.b , screen , 3 , &i); + affichage (C.I,screen); + pos (&M.dot , C.I.pos1.x-M.b[1].pos2.x*5 , C.I.pos1.y-M.b[1].pos2.y*5); + affichage (M.dot , screen); + afficheT((timeL-time)*0.001 , T , screen); + SDL_Flip (screen); + while (SDL_PollEvent (&event)) + { + switch (event.type) + { + case SDL_QUIT : + done = 1 ; + break; + case SDL_KEYUP: + direction=0; + break; + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_RIGHT ) + { + direction = 1; + } + else if (event.key.keysym.sym == SDLK_LEFT ) + { + direction = 2; + } + else if (event.key.keysym.sym == SDLK_UP ) + { + direction = 3; + } + else if (event.key.keysym.sym == SDLK_DOWN ) + { + direction = 4; + } + else if (event.key.keysym.sym == SDLK_ESCAPE ) + { + done =1; + } + + break ; + + } + + } + + if (startime==-1) + startime = SDL_GetTicks(); + + time = SDL_GetTicks() - startime; + + if (time==-1) + printf("\n%s",SDL_GetError()); + + if (i<=3-2) + i++; + else + i=0; + affichage ( mask , screen); + + collision (&C,mask,&done); + + if ( ( direction == 1 )&&(C.T[3].c==0) &&(C.I.pos1.x<5738) ) + { + C.I.pos1.x = C.I.pos1.x + 10 ; + } + if ( ( direction == 2 )&&(C.T[7].c==0)&&(C.I.pos1.x>10) ) + { + C.I.pos1.x = C.I.pos1.x - 10; + } + if ( ( direction == 3 )&&(C.T[1].c==0) ) + { + C.I.pos1.y = C.I.pos1.y - 10 ; + } + if ( ( direction == 4 )&&( C.T[5].c==0 ) ) + { + C.I.pos1.y = C.I.pos1.y + 10 ; + } + for ( j=0;j<3;j++) + scrollingMINI ( &M.b[j], direction ); + if (time - timeL>0) + { + done=1; + } + + + + + } + + freeAnime(M.b , 3 ) ; + freeAnime( bg , 3 ) ; + TTF_CloseFont(T.font); + //liberer (M.b); + liberer (mask); + liberer (C.I); + liberer (M.dot); + freeText( T); + SDL_Quit(); + TTF_Quit(); + return 0; +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..f34998c Binary files /dev/null and b/main.o differ diff --git a/makefile b/makefile new file mode 100644 index 0000000..713d705 --- /dev/null +++ b/makefile @@ -0,0 +1,9 @@ +prog : main.o minimap.o + gcc main.o minimap.o -o prog -lSDL -lSDL_image -lSDL_ttf + +main.o : main.c + gcc -c main.c + +minimap.o : minimap.c + gcc -c minimap.c + diff --git a/minimap.c b/minimap.c new file mode 100644 index 0000000..fc1a337 --- /dev/null +++ b/minimap.c @@ -0,0 +1,255 @@ +#include "minimap.h" + +void initMinimap (minimap *M) +{ + initAnime ( M->b , "images/mini/",".png",3,0,0,0,0,384,220) ; + + initdot(&M->dot); +} + + +void initback (image *B) +{ + B->img = SDL_LoadBMP ("images/masque_stage1.bmp"); + + B->pos1.x=0; + B->pos1.y=0; + B->pos2.x=0; + B->pos2.y=0; + B->pos2.w=B->img->w; + B->pos2.h = B->img->h; +} + + +void freeAnime (image T[],int n) +{ + int i; + for (i=0;iimg = IMG_Load ("images/back_button.png"); + B->pos1.x=30; + B->pos1.y=350; + B->pos2.x=0; + B->pos2.y=0; + B->pos2.w=B->img->w; + B->pos2.h = B->img->h; +} + +void initdot (image *D) +{ + D->img = IMG_Load ("images/dot.png"); + D->pos2.x=0; + D->pos2.y=0; + D->pos2.w=D->img->w; + D->pos2.h = D->img->h; +} + +void pos (image *D, float px , float py ) +{ + D->pos1.x= px*0.2035 ; + D->pos1.y=py*0.2035; + +} + +SDL_Color GetPixel(SDL_Surface *p , int x , int y) +{ + SDL_Color color; + Uint32 col=0; + + char * Pos = (char*)p->pixels; + Pos += (p->pitch * y); + Pos += (p->format->BytesPerPixel * x); + memcpy (&col ,Pos, p->format->BytesPerPixel ); + + SDL_GetRGB(col , p->format,&color.r , &color.g,&color.b ); + return color; + +} + + + +void scrollingMINI (image * b, int direction ) +{ + + if (direction==1) + { + /*if(b->pos2.x>2000) + { + b->pos2.x=0; + } + else*/ + if ( b->pos2.x+b->pos2.w <1158) + b->pos2.x+=2; + } + else if (direction==2) + /*if (b->pos2.x<0) + { + + } + else*/ + if ( b->pos2.x>0) + b->pos2.x-=2; + /*else if (direction==3) + if (b->pos2.y <-50) + { + + } + else + b->pos2.y=dx; + + else if (direction==4) + if (b->pos2.y> 150) + { + + } + else + b->pos2.y=dx;*/ +} + + + + + + + + + +void tab(perso *C) +{ + + C->T[0].x=C->I.pos1.x; + C->T[0].y=C->I.pos1.y; + C->T[0].c=0; + + C->T[1].x=C->I.pos1.x+C->I.pos2.w/2; + C->T[1].y=C->I.pos1.y; + C->T[1].c=0; + + C->T[2].x=C->I.pos1.x + C->I.pos2.w; + C->T[2].y=C->I.pos1.y; + C->T[2].c=0; + + C->T[3].x=C->I.pos1.x+C->I.pos2.w; + C->T[3].y=C->I.pos1.y + C->I.pos2.h /2; + C->T[3].c=0; + + C->T[4].x=C->I.pos1.x+C->I.pos2.w; + C->T[4].y=C->I.pos1.y+C->I.pos2.h; + C->T[4].c=0; + + C->T[5].x=C->I.pos1.x + C->I.pos2.w/2; + C->T[5].y=C->I.pos1.y+ C->I.pos2.h ; + C->T[5].c=0; + + C->T[6].x=C->I.pos1.x; + C->T[6].y=C->I.pos1.y+C->I.pos2.h; + C->T[6].c=0; + + C->T[7].x=C->I.pos1.x; + C->T[7].y=C->I.pos1.y+C->I.pos2.h/2; + C->T[7].c=0; + + +} + +void collision (perso *C , image B , int *done) +{ + SDL_Color color ,color2; + int i=0; + color.r=5; + color.g=5; + color.b=5; + tab(C); + while (i<8) + { + color2=GetPixel(B.img , C->T[i].x , C->T[i].y); + if ((color.r>=color2.r)&&(color.g>=color2.g)&&(color.b>=color2.b) ) + { + C->T[i].c = 1; + } + if ( ( i==3) && ((color.r==0)&&(color.g==0)&&(color.b==255) ) ) + *done=1; + i++; + } +} + +void initText( Text *A,int x,int y,int r,int g ,int b ,int n) +{ + A->position.x=x; + A->position.y=y; + A->textColor.r=r; + A->textColor.g=g; + A->textColor.b=b; + A->font=TTF_OpenFont ("AbrilFatface-Regular.ttf",n); +} + + +void afficheT (int t , Text T , SDL_Surface *screen ) +{ + char cht[6] , ch[15]; + sprintf(cht,"%d",t); + strcpy(ch,"temps :"); + strcat (ch , cht); + T.surfaceTexte = TTF_RenderText_Solid (T.font , ch , T.textColor); + SDL_BlitSurface ( T.surfaceTexte , NULL, screen , &T.position ); +} + +void freeText( Text A) +{ + SDL_FreeSurface ( A.surfaceTexte ); +} + + +void affichage (image M , SDL_Surface * screen) +{ + SDL_BlitSurface (M.img , &M.pos2 , screen , &M.pos1); +} + +void liberer(image M) +{ + SDL_FreeSurface(M.img); +} diff --git a/minimap.h b/minimap.h new file mode 100644 index 0000000..e2b715a --- /dev/null +++ b/minimap.h @@ -0,0 +1,72 @@ +#ifndef Minimap_H +#define Minimap_H +#include +#include +#include +#define SCREEN_W 1920 +#define SCREEN_H 1080 + + +typedef struct +{ + SDL_Rect position; + TTF_Font *font; + SDL_Surface *surfaceTexte; + SDL_Color textColor; + char texte [50]; +}Text ; + +typedef struct +{ + SDL_Rect pos1; + SDL_Rect pos2; + SDL_Surface *img ; +}image; + + +typedef struct +{ + image b[3]; + image dot; + +}minimap; + +typedef struct +{ + int x; + int y; + int c; +}point; + +typedef struct +{ + image I; + point T[8]; +}perso; + + +void initMinimap (minimap *M); +void init (image *M ); +void initdot (image *D); +void initback (image *B); +void initC (image *B); +void initText( Text *A,int x,int y,int r,int g ,int b ,int n); + + +void scrollingMINI (image * b, int direction ); +void freeAnime (image T[],int n); +void initAnime ( image T[] , char ch[] , char ext[] , int n , int x , int y , int x2 , int y2, int w , int h); +void playAnime2 (image T[], SDL_Surface *screen , int n,int *i); +void afficheT (int t , Text T , SDL_Surface *screen ); +void pos (image *D, float px , float py ); +void affichage (image M , SDL_Surface * screen); + +void tab(perso *C); +SDL_Color GetPixel(SDL_Surface *p , int x , int y); +void collision (perso *C , image B , int *done); +void liberer(image M); + +void freeText( Text A); + + +#endif diff --git a/minimap.o b/minimap.o new file mode 100644 index 0000000..148db0c Binary files /dev/null and b/minimap.o differ diff --git a/prog b/prog new file mode 100755 index 0000000..34c86b6 Binary files /dev/null and b/prog differ