From 44eb975c70d14c8bbb8e51340de8bc6f4ceda366 Mon Sep 17 00:00:00 2001 From: Pierre Cwik Date: Mon, 20 Jun 2016 17:07:51 +0200 Subject: [PATCH] snake bouge --- projets/Centipede/centipede | Bin 27992 -> 0 bytes projets/Centipede/progprinc.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ projets/Centipede/progprinc.o | Bin 6680 -> 0 bytes projets/Liste/libFile.c | 10 ++++++++++ projets/Liste/libFile.h | 5 ++++- projets/Liste/libFile.o | Bin 5112 -> 0 bytes projets/Liste/libListe.a | Bin 5292 -> 0 bytes 7 files changed, 100 insertions(+), 19 deletions(-) diff --git a/projets/Centipede/centipede b/projets/Centipede/centipede index 8a24682..97937ed 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 838af95..0afcaa0 100644 --- a/projets/Centipede/progprinc.c +++ b/projets/Centipede/progprinc.c @@ -4,6 +4,7 @@ #include #include #include +#include #define MAX_ELEMENTS 50 typedef struct { @@ -24,63 +25,130 @@ void affichage(element_t e) int main() { + SDL_keysym* detail; srand(time(NULL)); char touche; unsigned char bas; - void* detail; int largeur = 1000; int hauteur = 1000; liste_champi muschrooms={.nombre=0}; + liste_t listecenti={NULL,0,0}; int h,w,l,i; char *titre = "Le Centipède"; - creerSurface(largeur,hauteur,titre); + int champi = chargerLutin("Lutins/millepatte_champi.bmp",0); - if(champi<0){ printf("Champi pas là\n"); exit(-1); } 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); */ + + if(champi<0){ printf("Champi pas là\n"); exit(-1); } tailleLutin(champi,&l,&h); + + + position *pos; position poschampi; + position posmillepatte; - int x = (rand()%20)*50+2; - int y = (rand()%20)*50; - afficherLutin(Teted,x,y); + 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); + 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; + poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons poschampi.y = (rand()%20)*50; - muschrooms.contenu[muschrooms.nombre++]=poschampi; + if(poschampi.y > 550 || poschampi.y < 450) { + 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); - } - majSurface(); + }//affiche les champis + majSurface(); + + int gomme = creerLutin(0,0,50,50,0); + majSurface(); while(1){ - while(!lireTouche(&bas,&touche,&detail)); - printf("%d %c\n",bas,touche); + 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(touche=='a') { - fermerSurface(); + fermerSurface(); //condition d'arret return 0; } - } + }} return 0; } - \ No newline at end of file + diff --git a/projets/Centipede/progprinc.o b/projets/Centipede/progprinc.o index 0f3f838..d10ff3e 100644 Binary files a/projets/Centipede/progprinc.o and b/projets/Centipede/progprinc.o differ diff --git a/projets/Liste/libFile.c b/projets/Liste/libFile.c index c1b0b72..2a69f9d 100644 --- a/projets/Liste/libFile.c +++ b/projets/Liste/libFile.c @@ -43,3 +43,13 @@ int defiler(liste_t *l) } return 0; } + +element_t premier(liste_t *l) { + return l->contenu[0]; } + +element_t dernier(liste_t *l) { + return l->contenu[(l->nombre)-1];} + +element_t enieme(int x, liste_t *l) { + return l->contenu[x]; +} diff --git a/projets/Liste/libFile.h b/projets/Liste/libFile.h index df7dfb9..dbf391f 100644 --- a/projets/Liste/libFile.h +++ b/projets/Liste/libFile.h @@ -7,6 +7,9 @@ typedef void *element_t; } liste_t; int taille(liste_t *l); -int enfiler (liste_t *l, element_t e, int taille); +int enfiler (liste_t *l,element_t e, int taille); int afficher (liste_t *l, void(*affichage)(element_t)); int defiler(liste_t *l); +element_t dernier(liste_t *l); +element_t premier(liste_t *l); +element_t enieme(int x, liste_t *l); diff --git a/projets/Liste/libFile.o b/projets/Liste/libFile.o index d18b9be..bea6a6a 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 6195863..8339822 100644 Binary files a/projets/Liste/libListe.a and b/projets/Liste/libListe.a differ -- libgit2 0.21.2