From c3040ffaee534eae000268533bf2a003dac89028 Mon Sep 17 00:00:00 2001 From: Pierre Cwik Date: Wed, 22 Jun 2016 11:58:39 +0200 Subject: [PATCH] avec game over --- projets/Centipede/centipede | Bin 32896 -> 0 bytes projets/Centipede/progprinc.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------ projets/Centipede/progprinc.c~ | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ projets/Centipede/progprinc.o | Bin 19376 -> 0 bytes projets/Graphique/libgraph.a | Bin 31830 -> 0 bytes projets/Liste/libFile.c | 4 ++-- projets/Liste/libFile.o | Bin 5800 -> 0 bytes projets/Liste/libListe.a | Bin 6016 -> 0 bytes projets/Lutins/game_over.bmp | Bin 0 -> 199554 bytes projets/Testliste/projet | Bin 10368 -> 0 bytes 10 files changed, 367 insertions(+), 80 deletions(-) create mode 100644 projets/Centipede/progprinc.c~ create mode 100644 projets/Lutins/game_over.bmp mode change 100755 => 100644 projets/Testliste/projet diff --git a/projets/Centipede/centipede b/projets/Centipede/centipede index 97937ed..ba965fa 100755 Binary files a/projets/Centipede/centipede and b/projets/Centipede/centipede differ diff --git a/projets/Centipede/progprinc.c b/projets/Centipede/progprinc.c index 0afcaa0..3a83093 100644 --- a/projets/Centipede/progprinc.c +++ b/projets/Centipede/progprinc.c @@ -33,24 +33,28 @@ int main() { int hauteur = 1000; liste_champi muschrooms={.nombre=0}; liste_t listecenti={NULL,0,0}; - int h,w,l,i; + int h,w,l,i,t, allonge; + int s=0; 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 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 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 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; + + 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); } - if(champi<0){ printf("Champi pas là\n"); exit(-1); } tailleLutin(champi,&l,&h); - - position *pos; position poschampi; position posmillepatte; @@ -60,18 +64,18 @@ int main() { int x = 300; int y = 500; - for(i=0; i<4; i++) - { - posmillepatte.x = (x + 50*i); - posmillepatte.y = y; - enfiler(&listecenti,&posmillepatte,sizeof(position)); - } + for(i=0; i<4; i++) + { + posmillepatte.x = (x + 50*i); + posmillepatte.y = y; + enfiler(&listecenti,&posmillepatte,sizeof(position)); + } //affichage des corpsd du centipede - for(i=0; i<4; i++) - { - pos = enieme(i,&listecenti); - afficherLutin(Corpsd,pos->x,pos->y); - } + for(i=0; i<4; i++) + { + pos = enieme(i,&listecenti); + afficherLutin(Corpsd,pos->x,pos->y); + } posmillepatte.x = (x+200); posmillepatte.y = y; @@ -79,76 +83,135 @@ int main() { pos = enieme(4, &listecenti); afficherLutin(Teted,pos->x,pos->y); - for(i = 0 ; i < 20; i++) - { - rectanglePlein(i*50,0,1,1000,5); //pose de la grille - rectanglePlein(0,i*50,1000,1,5); - } - - for(w=0;w<10;w++) { - poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons - poschampi.y = (rand()%20)*50; - if(poschampi.y > 550 || poschampi.y < 450) { - muschrooms.contenu[muschrooms.nombre++]=poschampi; } - else w--; - } +/* for(i = 0 ; i < 20; i++) + { + rectanglePlein(i*50,0,1,1000,5); //pose de la grille + rectanglePlein(0,i*50,1000,1,5); + } */ + + + for(w=0;w<20;w++) + { + poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons + poschampi.y = (rand()%20)*50; + if(poschampi.y > 570 || poschampi.y < 430) + { + muschrooms.contenu[muschrooms.nombre++]=poschampi; + afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6); + } + else w--; + } printf("%d %d \n",l,h); - - for(w=0;w<10;w++){ - afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6); - }//affiche les champis - majSurface(); - - int gomme = creerLutin(0,0,50,50,0); - majSurface(); + //affiche les champis + for(w=0;w<20;w++) + { + printf("les coordonnées de mes champis : %d %d \n", (muschrooms.contenu[w].x),(muschrooms.contenu[w].y)); + } + + majSurface(); + + int gomme = creerLutin(0,0,50,50,-1); + +/* afficherLutin(Corpsd,0,0) + int couleurcd = couleurPixel(25,25); + majSurface(); + afficherLutin(gomme,0,0); + majSurface(); + + afficherLutin(Corpsg,0,0) + int couleurcg = couleurPixel(25,25); + majSurface(); + afficherLutin(gomme,0,0); + majSurface(); + + afficherLutin(Corpsh,0,0) + int couleurch = couleurPixel(25,25); + majSurface(); + afficherLutin(gomme,0,0); + majSurface(); + + afficherLutin(Corpsb,0,0) + int couleurcb = couleurPixel(25,25); + majSurface(); + afficherLutin(gomme,0,0); + majSurface(); */ + + majSurface(); while(1){ - if(lireTouche(&bas,&touche,(void **)&detail) && bas==1) { - - if(detail->sym==SDLK_RIGHT) { - printf("dans le droite\n"); - pos = premier(&listecenti); - afficherLutin(gomme,pos->x,pos->y); - defiler(&listecenti); - - pos = dernier(&listecenti); - afficherLutin(gomme,pos->x,pos->y); - afficherLutin(Corpsd,(pos->x),pos->y); - posmillepatte.x = pos->x+50; - posmillepatte.y = pos->y; - enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); - afficherLutin(Teted,posmillepatte.x,posmillepatte.y); - majSurface(); - } - - if(detail->sym==SDLK_LEFT) { - - } - - if(detail->sym==SDLK_UP) { - - } - - if(detail->sym==SDLK_DOWN) { - - } - - - + 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(200000); + + 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); + fermerSurface(); + } + + majSurface(); + couleur = couleurPixel(posmillepatte.x+25,posmillepatte.y+25); + printf("la couleur est %d\n",couleur); + if(couleur!=1) obstacle = 1; + else obstacle = 0; + allonge = 0; + + if(obstacle==1){ + for(w=0;w<20;w++) + { + if((muschrooms.contenu[w].x) == posmillepatte.x && (muschrooms.contenu[w].y) == posmillepatte.y) { allonge = 1; } } + if(allonge==1){ + afficherLutin(gomme,pos->x,pos->y); + afficherLutin(Corps,(pos->x),pos->y); + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); + afficherLutin(Tete,posmillepatte.x,posmillepatte.y); + } + else { + afficherLutin(gameover,250,433); + majSurface(); + sleep(5); + fermerSurface(); + } + + } + + 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(touche=='a') { fermerSurface(); //condition d'arret - return 0; - + return 0; } - }} - - +} return 0; } - + \ No newline at end of file diff --git a/projets/Centipede/progprinc.c~ b/projets/Centipede/progprinc.c~ new file mode 100644 index 0000000..a834742 --- /dev/null +++ b/projets/Centipede/progprinc.c~ @@ -0,0 +1,224 @@ +#include +#include +#include +#include +#include +#include +#include +#define MAX_ELEMENTS 50 + +typedef struct { + int x; + int y; +}position; + +typedef struct { + position contenu[MAX_ELEMENTS]; + int nombre; + } liste_champi; + +void affichage(element_t e) +{ + position *p = e; + printf("%d %d \n", p->x, p->y); +} + + +int main() { + SDL_keysym* detail; + srand(time(NULL)); + char touche; + unsigned char bas; + int largeur = 1000; + int hauteur = 1000; + liste_champi muschrooms={.nombre=0}; + liste_t listecenti={NULL,0,0}; + int h,w,l,i,t; + int s=10; + 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); + + if(champi<0){ printf("Champi pas là\n"); exit(-1); } + tailleLutin(champi,&l,&h); + + + position *pos; + position poschampi; + position posmillepatte; + + creerSurface(largeur,hauteur,titre); + + int x = 300; + int y = 500; + + for(i=0; i<4; i++) + { + posmillepatte.x = (x + 50*i); + posmillepatte.y = y; + enfiler(&listecenti,&posmillepatte,sizeof(position)); + } + //affichage des corpsd du centipede + for(i=0; i<4; i++) + { + pos = enieme(i,&listecenti); + afficherLutin(Corpsd,pos->x,pos->y); + } + + posmillepatte.x = (x+200); + posmillepatte.y = y; + enfiler(&listecenti,&posmillepatte,sizeof(position)); //affichage de la tete du Centipède + pos = enieme(4, &listecenti); + afficherLutin(Teted,pos->x,pos->y); + + for(i = 0 ; i < 20; i++) + { + rectanglePlein(i*50,0,1,1000,5); //pose de la grille + rectanglePlein(0,i*50,1000,1,5); + } + + for(w=0;w<10;w++) { + poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons + poschampi.y = (rand()%20)*50; + if(poschampi.y > 570 || poschampi.y < 430) { + muschrooms.contenu[muschrooms.nombre++]=poschampi; } + else w--; + } + + printf("%d %d \n",l,h); + + for(w=0;w<10;w++){ + afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6); + }//affiche les champis + majSurface(); + + int gomme = creerLutin(0,0,50,50,0); + 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(500000); + + if((t==0 && s!=2) || s==0) { + printf("dans le droite\n"); + pos = premier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + defiler(&listecenti); + + pos = dernier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + afficherLutin(Corpsd,(pos->x),pos->y); + posmillepatte.x = pos->x+50; + posmillepatte.y = pos->y; + if(posmillepatte.x > 1000 || posmillepatte.y > 1000 || posmillepatte.x < 0 || posmillepatte.y < 0){ + afficherLutin(gameover,400,400); + majSurface(); + sleep(5); + fermerSurface(); + } + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); + afficherLutin(Teted,posmillepatte.x,posmillepatte.y); + majSurface(); + s=0; + } + + if((t==1 && s!=3) || s==1) { + printf("dans le haut\n"); + pos = premier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + defiler(&listecenti); + + pos = dernier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + afficherLutin(Corpsh,(pos->x),pos->y); + posmillepatte.x = pos->x; + posmillepatte.y = pos->y-50; + if(posmillepatte.x > 1000 || posmillepatte.y > 1000 || posmillepatte.x < 0 || posmillepatte.y < 0){ + afficherLutin(gameover,400,400); + majSurface(); + sleep(5); + fermerSurface(); + } + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); + afficherLutin(Teteh,posmillepatte.x,posmillepatte.y); + majSurface(); + s=1; + } + + if((t==2 && s!=0) || s==2) { + printf("dans le gauche\n"); + pos = premier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + defiler(&listecenti); + + pos = dernier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + afficherLutin(Corpsg,(pos->x),pos->y); + posmillepatte.x = pos->x-50; + posmillepatte.y = pos->y; + if(posmillepatte.x > 1000 || posmillepatte.y > 1000 || posmillepatte.x < 0 || posmillepatte.y < 0){ + afficherLutin(gameover,400,400); + majSurface(); + sleep(5); + fermerSurface(); + } + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); + afficherLutin(Teteg,posmillepatte.x,posmillepatte.y); + majSurface(); + s=2; + } + + if((t==3 && s!=1) || s==3) { + printf("dans le bas\n"); + pos = premier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + defiler(&listecenti); + + pos = dernier(&listecenti); + afficherLutin(gomme,pos->x,pos->y); + afficherLutin(Corpsb,(pos->x),pos->y); + posmillepatte.x = pos->x; + posmillepatte.y = pos->y+50; + if(posmillepatte.x > 1000 || posmillepatte.y > 1000 || posmillepatte.x < 0 || posmillepatte.y < 0){ + afficherLutin(gameover,400,400); + majSurface(); + sleep(5); + fermerSurface(); + } + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte)); + afficherLutin(Teteb,posmillepatte.x,posmillepatte.y); + majSurface(); + s=3; + } + + if(touche=='a') + { + fermerSurface(); //condition d'arret + return 0; + + } +} + + + return 0; +} + + diff --git a/projets/Centipede/progprinc.o b/projets/Centipede/progprinc.o index d10ff3e..34b568c 100644 Binary files a/projets/Centipede/progprinc.o and b/projets/Centipede/progprinc.o differ diff --git a/projets/Graphique/libgraph.a b/projets/Graphique/libgraph.a index 7833a2d..2789297 100644 Binary files a/projets/Graphique/libgraph.a and b/projets/Graphique/libgraph.a differ diff --git a/projets/Liste/libFile.c b/projets/Liste/libFile.c index 2a69f9d..1d4d6be 100644 --- a/projets/Liste/libFile.c +++ b/projets/Liste/libFile.c @@ -13,8 +13,8 @@ element_t nouveau=malloc(taille); memcpy(nouveau,e,taille); if (l->nombre >= l->alloue) { - l->contenu = realloc(l->contenu, l->alloue+100); - l->alloue+=100; + l->contenu = realloc(l->contenu, l->alloue+300); + l->alloue+=300; } l->contenu[l->nombre++]=nouveau; return 0; diff --git a/projets/Liste/libFile.o b/projets/Liste/libFile.o index bea6a6a..1599463 100644 Binary files a/projets/Liste/libFile.o and b/projets/Liste/libFile.o differ diff --git a/projets/Liste/libListe.a b/projets/Liste/libListe.a index 8339822..cfcf6c3 100644 Binary files a/projets/Liste/libListe.a and b/projets/Liste/libListe.a differ diff --git a/projets/Lutins/game_over.bmp b/projets/Lutins/game_over.bmp new file mode 100644 index 0000000..9320d63 Binary files /dev/null and b/projets/Lutins/game_over.bmp differ diff --git a/projets/Testliste/projet b/projets/Testliste/projet old mode 100755 new mode 100644 index fc98fda..fc98fda Binary files a/projets/Testliste/projet and b/projets/Testliste/projet differ -- libgit2 0.21.2