From f9e066da8d1363925e7fdeed8fd723c62ff4511a Mon Sep 17 00:00:00 2001 From: JUDE CHRIST AISSI Date: Thu, 21 Dec 2023 14:55:45 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9glage=20collision=20+=20ajout=20t=C3=AAt?= =?UTF-8?q?e=20serpent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SAE_semestre1/fichier.h/serpent.h | 1 + SAE_semestre1/src/main.c | 5 +++-- SAE_semestre1/src/serpent.c | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SAE_semestre1/fichier.h/serpent.h b/SAE_semestre1/fichier.h/serpent.h index a63307d..c1b9e68 100755 --- a/SAE_semestre1/fichier.h/serpent.h +++ b/SAE_semestre1/fichier.h/serpent.h @@ -5,4 +5,5 @@ void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, i void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on); void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int*); void Controle(int *direction, int last_direction, int *go_on, int *pause); +void dessinerSerpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]); #endif diff --git a/SAE_semestre1/src/main.c b/SAE_semestre1/src/main.c index c0e41d5..62fadb1 100644 --- a/SAE_semestre1/src/main.c +++ b/SAE_semestre1/src/main.c @@ -42,20 +42,21 @@ int lancer_jeu(){ InitialiserOeufs(oeufx, oeufy, segment); Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, &go_on, pointeur_direction); bordure(segment); + Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction); while(go_on==1){ Controle(pointeur_direction, 0, &go_on, pointeur_pause); if(pause == 1){ Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer); Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction); + dessinerSerpent(pos_x, pos_y, segment, old_x, old_y); Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on); - usleep(100000); + usleep(90000); Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment); } } } int main(void){ int choix = 0; - int go_on = 1; InitialiserGraphique(); CreerFenetre(350,100,1200,900); EffacerEcran(CouleurParComposante(0,0,0)); diff --git a/SAE_semestre1/src/serpent.c b/SAE_semestre1/src/serpent.c index 049dee6..4b76867 100755 --- a/SAE_semestre1/src/serpent.c +++ b/SAE_semestre1/src/serpent.c @@ -10,33 +10,40 @@ void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_ if (*direction == 1){ pos_y[0]=old_y[0]-20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 2) { pos_y[0]=old_y[0]+20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 3) { pos_x[0]=old_x[0]-20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 4) { pos_x[0]=old_x[0]+20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } + return; +} + +void dessinerSerpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){ + int i; for (i=0 ; i1180 || pos_x[0]<=0){ + if (pos_x[0] >1160 || pos_x[0]<=0){ *go_on=0; } /*Serpent contre coté*/ @@ -55,6 +62,7 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu *go_on=0; } } + return; } void Controle(int *direction, int last_direction, int *go_on, int *pause) {