#include #include #include #include #include #include #include #define MAX_ELEMENTS 50 typedef struct{ char pseudo; char scoremax; }scorejoueur; typedef struct { int x; int y; }position; typedef struct { position contenu[MAX_ELEMENTS]; int nombre; } liste_champi; void creationgrille(){ int i; for(i = 0 ; i < 20; i++) { rectanglePlein(i*50,0,1,1000,5); //pose de la grille rectanglePlein(0,i*50,1000,1,5); } } void affichage(element_t e) { position *p = e; printf("%d %d \n", p->x, p->y); } void creerchampignons(int n,liste_champi *muschrooms,int champi){ position poschampi; int i,w; int test=0; for(w=0;wcontenu[i].x == poschampi.x && muschrooms->contenu[i].y == poschampi.y ) test=1; } if((poschampi.y > 570 || poschampi.y < 430) && test==0) { muschrooms->contenu[muschrooms->nombre++]=poschampi; afficherLutin(champi,(muschrooms->contenu[w].x)+1,(muschrooms->contenu[w].y)+6); } else w--; test = 0; } } void creationcenti(liste_t *l, int Teted, int Corpsd){ int i; position *pos; position posmillepatte; for(i=0; i<4; i++) { posmillepatte.x = (300 + 50*i); posmillepatte.y = 500; enfiler(l,&posmillepatte,sizeof(position)); } //affichage des corpsd du centipede for(i=0; i<4; i++) { pos = enieme(i,l); afficherLutin(Corpsd,pos->x,pos->y); } posmillepatte.x = 500; posmillepatte.y = 500; enfiler(l,&posmillepatte,sizeof(position)); //affichage de la tete du Centipède pos = enieme(4, l); afficherLutin(Teted,pos->x,pos->y); } int main() { SDL_keysym* detail; srand(time(NULL)); char touche; unsigned char bas; int largeur = 1000; int hauteur = 1000; char *titre = "Le Centipède"; int champi = chargerLutin("Lutins/millepatte_champi.bmp",0); int Teted = chargerLutin("Lutins/millepatte_tete_droite.bmp",0); int Teteg = chargerLutin("Lutins/millepatte_tete_gauche.bmp",0); int Teteh = chargerLutin("Lutins/millepatte_tete_haut.bmp",0); int Teteb = chargerLutin("Lutins/millepatte_tete_bas.bmp",0); int Corpsg = chargerLutin("Lutins/millepatte_corps_gauche.bmp",0); int Corpsd = chargerLutin("Lutins/millepatte_corps_droite.bmp",0); int Corpsh = chargerLutin("Lutins/millepatte_corps_haut.bmp",0); int Corpsb = chargerLutin("Lutins/millepatte_corps_bas.bmp",0); int gameover = chargerLutin("Lutins/game_over.bmp",0); int Tete; int Corps; int abs, ord, obstacle, couleur,level=1,speed=200000,total=0,nombrechampis=3; if(champi<0 || Teted<0 || Teteg<0 || Teteh <0 || Teteb<0 || Corpsg<0 || Corpsd<0 || Corpsh<0 || Corpsb<0 || gameover<0){ printf("Image pas là\n"); exit(-1); } FILE *fichier = fopen("fichierdesscores.txt",a+); printf("joueur !! quel est votre pseudo ? :"); scanf("%s",&pseudo); while(level<5) { liste_champi muschrooms={.nombre=0}; liste_t listecenti={NULL,0,0}; int h,w,l,t,compteur=0,allonge; int s=10; tailleLutin(champi,&l,&h); position *pos; position posmillepatte; creerSurface(largeur,hauteur,titre); creationcenti(&listecenti,Teted,Corpsd); creerchampignons(nombrechampis,&muschrooms,champi); majSurface(); int gomme = creerLutin(0,0,50,50,-1); majSurface(); while(1){ if(lireTouche(&bas,&touche,(void **)&detail) && bas==1) { if(detail->sym==SDLK_RIGHT) t=0; if(detail->sym==SDLK_UP) t=1; if(detail->sym==SDLK_LEFT) t=2; if(detail->sym==SDLK_DOWN) t=3; } usleep(speed); if((t==0 && s!=2) || s==0) { abs=50; ord=0; Tete = Teted; Corps = Corpsd; s=0; } if((t==1 && s!=3) || s==1) { abs=0; ord=(-50); Tete = Teteh; Corps = Corpsh; s=1; } if((t==2 && s!=0) || s==2) { abs=-50; ord=0; Tete = Teteg; Corps = Corpsg; s=2; } if((t==3 && s!=1) || s==3) { abs=0; ord=50; Tete = Teteb; Corps = Corpsb; s=3; } pos = dernier(&listecenti); posmillepatte.x = pos->x+abs; posmillepatte.y = pos->y+ord; if(posmillepatte.x==1000 || posmillepatte.y==1000 || posmillepatte.x==-50 || posmillepatte.y==-50) { afficherLutin(gameover,250,433); majSurface(); sleep(5); break; } majSurface(); couleur = couleurPixel(posmillepatte.x+25,posmillepatte.y+25); if(couleur!=1) obstacle = 1; else obstacle = 0; allonge = 0; if(obstacle==1){ for(w=0;wx,pos->y); afficherLutin(Corps,(pos->x),pos->y); enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); afficherLutin(Tete,posmillepatte.x,posmillepatte.y); compteur++; } else { afficherLutin(gameover,250,433); majSurface(); sleep(5); break; } } if(obstacle==0){ afficherLutin(gomme,pos->x,pos->y); afficherLutin(Corps,(pos->x),pos->y); enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); afficherLutin(Tete,posmillepatte.x,posmillepatte.y); pos = premier(&listecenti); afficherLutin(gomme,pos->x,pos->y); defiler(&listecenti); } majSurface(); if(compteur==nombrechampis) break; if(touche=='a') { fermerSurface(); //condition d'arret return 0; } } total = total+compteur; if(compteur != nombrechampis) break; compteur = 0; nombrechampis = nombrechampis+3; speed = speed/1.2; level++; } printf("votre score est de %d\n",total); fermerSurface(); fclose(fichier); return 0; }