réglage collision + ajout tête serpent

This commit is contained in:
JUDE CHRIST AISSI 2023-12-21 14:55:45 +01:00
parent d0285048f5
commit f9e066da8d
3 changed files with 17 additions and 7 deletions

View File

@ -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

View File

@ -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));

View File

@ -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 ; i<segment ; i++){
ChargerImage("../img/serpent2.png", pos_x[i], pos_y[i],0,0, 20,20);
ChargerImage("../img/serpent2.png", old_x[i], old_y[i],0,0, 20,20);
}
for (i=0 ; i<segment ; i++){
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
RemplirRectangle(pos_x[segment-1], pos_y[segment-1], 20,20);
RemplirRectangle(old_x[segment-1], old_y[segment-1], 20,20);
old_x[i]=pos_x[i];
old_y[i]=pos_y[i];
}
}
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){
int i;
/*Serpent contre coté*/
if (pos_x[0] >1180 || 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) {